Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Can Anyone Help Me With This?


Mort-lemur

Recommended Posts

Hi,

 

I want to add some code in my admin side so that when I enter a products model when creating a new product, a query is made of the database and an error is given if that model number already exists.

 

This is similar to the email check when a customer creates an account.

 

I know (think) that I need to modify Categories_php with a query and database check, but its beyond my current capability.

 

Would love some help

 

Thanks

Now running on a fully modded, Mobile Friendly 2.3.4 Store with the Excellent MTS installed - See my profile for the mods installed ..... So much thanks for all the help given along the way by forum members.

Link to comment
Share on other sites

Hi,

 

I want to add some code in my admin side so that when I enter a products model when creating a new product, a query is made of the database and an error is given if that model number already exists.

 

This is similar to the email check when a customer creates an account.

 

I know (think) that I need to modify Categories_php with a query and database check, but its beyond my current capability.

 

Would love some help

 

Thanks

Are you game to doing some research and figuring it out on your own, with pointers in the right direction?

 

In the php file that inputs the new item create a function (use other files to see the way functions work) that checks the database for the model that is being entered. The sql in the function will be something like this...

 

select count(*) from products where products_model = the_products_model_field_name

 

You will want to display a pop up when the select returns anything other than '0 rows returned.'

 

As anything else, there is always more than one way to do things. this one should be pretty simple.

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Are you game to doing some research and figuring it out on your own, with pointers in the right direction?

 

In the php file that inputs the new item create a function (use other files to see the way functions work) that checks the database for the model that is being entered. The sql in the function will be something like this...

 

select count(*) from products where products_model = the_products_model_field_name

 

You will want to display a pop up when the select returns anything other than '0 rows returned.'

 

As anything else, there is always more than one way to do things. this one should be pretty simple.

 

Thanks I will try ! but not finding it simples !

Now running on a fully modded, Mobile Friendly 2.3.4 Store with the Excellent MTS installed - See my profile for the mods installed ..... So much thanks for all the help given along the way by forum members.

Link to comment
Share on other sites

Another hint: To trigger the function call, set the onBlur="function_name" within the <input type> container.

 

But, I'm no expert so I would be doing a ton of research and trial & error to get this to work myself. Hopefully someone else will give you more specific help.

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Thanks for your help so far Mark,

 

The code I'm looking to modify from "create_account.php" and insert into Admin/Categories.php to check for a duplicate model number then throw up an error message is:

 

      $check_email_query = tep_db_query("select count(*) as total from " . TABLE_CUSTOMERS . " where guest_account != 1 and customers_email_address = '" . tep_db_input($email_address) . "'");
     $check_email = tep_db_fetch_array($check_email_query);
     if ($check_email['total'] > 0) {
       $error = true;

       $messageStack->add('create_account', ENTRY_EMAIL_ADDRESS_ERROR_EXISTS);
     }
   }

 

But Im struggling modding it and finding where to put the code in Categories.php

 

Thanks

Now running on a fully modded, Mobile Friendly 2.3.4 Store with the Excellent MTS installed - See my profile for the mods installed ..... So much thanks for all the help given along the way by forum members.

Link to comment
Share on other sites

Hi,

 

I'm sure this is not that difficult for someone knowledgeable in PHP, but every time I try to modify to do a Products_model check it gives me lots of errors.

 

I'll keep trying, but may have to give up soon.

 

Thanks

Now running on a fully modded, Mobile Friendly 2.3.4 Store with the Excellent MTS installed - See my profile for the mods installed ..... So much thanks for all the help given along the way by forum members.

Link to comment
Share on other sites

$check_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " where products_model = '" . tep_db_input($products_model) . "'");
     $check_model = tep_db_fetch_array($check_products_query);
     if ($check_model['total'] > 0) {
       $error = true;

 

Is this what you have?

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Hi, Mine was almost like that :'(

 

So now I have added this to my admin/categories.php:

tep_draw_input_field('products_quantity', $pInfo->products_quantity); ?></td>
         </tr>
         <tr>
           <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
         </tr>
         <tr>
           <td class="main"><?php echo TEXT_PRODUCTS_MODEL; ?></td>
           <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_model', $pInfo->products_model); 
		// MODEL NO BOF
		$check_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " where products_model = '" . tep_db_input($products_model) . "'");
     $check_model = tep_db_fetch_array($check_products_query);
     if ($check_model['total'] > 0) {
       $error = true;

   $messageStack->add(ENTRY_MODEL_ERROR, 'error');
}
		//MODEL NO EOF
		?></td>
         </tr>

 

And this to my admin/.....english.php:

 

define('ENTRY_MODEL_ERROR', 'Error: That Model Number Has Already Been Used.');

 

There are no errors - but it does not stop me inserting a duplicate model No.

 

What should I look for next ?

 

Thanks

Now running on a fully modded, Mobile Friendly 2.3.4 Store with the Excellent MTS installed - See my profile for the mods installed ..... So much thanks for all the help given along the way by forum members.

Link to comment
Share on other sites

Find the function that is triggered with the $message_stack entry. Something is responsible for popping up an error or displaying the notation to you that prevents you from continuing.

 

 

Actually, now that I look at it, the script has all the functions to complete the process in a container with the if conditional....

 

if ($error == false) {
do these things to enter into database.
...
...
}

 

But I do not see and 'else' code in there.

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Hi again,

 

This is consuming many hours at the moment....

 

Now my code in Categories.php looks like this:

 

// check if the catalog image directory exists
 if (is_dir(DIR_FS_CATALOG_IMAGES)) {
   if (!is_writeable(DIR_FS_CATALOG_IMAGES)) $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_NOT_WRITEABLE, 'error');
 } else {
   $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_DOES_NOT_EXIST, 'error');
 }
 			// MODEL NO BOF
		$check_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " where products_model = '" . tep_db_input($products_model) . "'");
     $check_products_model = tep_db_fetch_array($check_products_query);
     if ($check_products_model['total'] > 0) $messageStack->add(ENTRY_MODEL_ERROR, 'error');





		//MODEL NO EOF
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

 

No errors are given, but the error message is now always on whenever I am on the admin/categories.php page - its like it is doing the query but I think i need to add an if or an else statement ?

 

Thanks

Now running on a fully modded, Mobile Friendly 2.3.4 Store with the Excellent MTS installed - See my profile for the mods installed ..... So much thanks for all the help given along the way by forum members.

Link to comment
Share on other sites

I remember seeing where it turns off all the messages (sets them to false) somewhere to initialize them. Look in your sample create_account.hp for where it initializes the message stack, and duplicate that in your categories.php

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

The other (and possibly easier method) is to make a javascript check on the product_model and return a "used" or "available" message on the fly.

 

This is done a lot for checking the availability of usernames on forums and the like. Have a hunt in Google, I bet you can find an easy to follow tutorial.

Link to comment
Share on other sites

3 days of posting back and forth hasn't gotten this to the stage of "it works". Hence why I posted with an idea for an alternative [and easier in my opinion] solution - that's all. Meant no disrespect to how you have helped Mort-Lemur.

Link to comment
Share on other sites

3 days of posting back and forth hasn't gotten this to the stage of "it works". Hence why I posted with an idea for an alternative [and easier in my opinion] solution - that's all. Meant no disrespect to how you have helped Mort-Lemur.

None taken, but she is learning while doing. Next time she may select a different method. And if you look I actually did suggest a javascript function at first and she elected to use methods already incorporated in osC and keep everything consistent. I actually agree with her choice.

 

Rock on girl. You're only a step away.

 

Another hint.. since the script calls itself to complete the entry of the product it must display the error on the same page. Clear the error in the code that includes a successful entry of the product and it will not be shown on the reload of the page.

 

i.e.

if ($error == false) {
do these things to enter into database.
...
...
$error=false;  // or maybe there is a function to remove the specific message from the message stack...
}

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Hi,

 

Thanks for all the help so far

 

Im at the stage now where my duplicate model warning is showing all the time - when I am on the admin/categories page.

 

I cannot find a code to turn it off, and Im not even sure if its because I have put the code snippet in the wrong part of the php file.

 

I may look at Java, but that is even more alien to me than php.

 

Thanks

Now running on a fully modded, Mobile Friendly 2.3.4 Store with the Excellent MTS installed - See my profile for the mods installed ..... So much thanks for all the help given along the way by forum members.

Link to comment
Share on other sites

Hi,

 

Thanks for all the help so far

 

Im at the stage now where my duplicate model warning is showing all the time - when I am on the admin/categories page.

 

I cannot find a code to turn it off, and Im not even sure if its because I have put the code snippet in the wrong part of the php file.

 

I may look at Java, but that is even more alien to me than php.

 

Thanks

It's probably because the categories.php page is also used for adding categories and updating products as well, and you need to trap for the error ONLY on adding a product. Here is the portion of code that does this...

 

        if ($action == 'insert_product') {
           $insert_sql_data = array('products_date_added' => 'now()');

           $sql_data_array = array_merge($sql_data_array, $insert_sql_data);

           tep_db_perform(TABLE_PRODUCTS, $sql_data_array);
           $products_id = tep_db_insert_id();

           tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)$products_id . "', '" . (int)$current_category_id . "')");
         } elseif ($action == 'update_product') {

 

So, within this code only, you need to trap for the error... remember above where I said...

if ($error == false) {
do these things to enter into database.
...
...
}

Your code determines if the model was used and sets the error flag. The above code eeither allows or disallows the db write based on the error flag.

 

Merge those two codes together to do what you want, and add the code (in your section of code) to reset the error to false when a dup is not found. Then I think you might have it.

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Hi,

 

Been trying this for the past 2 hours now, merging in different places, with and without various brackets, various IF and ELSEIF statements, but none seem to work for me.

 

The section now looks like this:

 

          if ($action == 'insert_product') {

           $insert_sql_data = array('products_date_added' => 'now()');
// MODEL NO BOF
           $check_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " where products_model = '" . tep_db_input($products_model) . "'");
     $check_model = tep_db_fetch_array($check_products_query);
     if ($check_model['total'] > 0) {
       $error = true; 
	$messageStack->add(ENTRY_MODEL_ERROR, 'error');
    if ($error == false) {
 }
 }
         			//MODEL NO EOF
           $sql_data_array = array_merge($sql_data_array, $insert_sql_data);

           tep_db_perform(TABLE_PRODUCTS, $sql_data_array);
           $products_id = tep_

 

I have tried adding duplicate model numbers - and I do not get the error message - ie. it lets me add duplicates without warning me.

 

Thanks

Now running on a fully modded, Mobile Friendly 2.3.4 Store with the Excellent MTS installed - See my profile for the mods installed ..... So much thanks for all the help given along the way by forum members.

Link to comment
Share on other sites

Only one (or 2?) steps away now - just need some help with the final bit....

 

What is wrong with my code above??

 

Thanks

Now running on a fully modded, Mobile Friendly 2.3.4 Store with the Excellent MTS installed - See my profile for the mods installed ..... So much thanks for all the help given along the way by forum members.

Link to comment
Share on other sites

Mort, you probably want the error message to be in the product preview portion, and not really prevent you from doing the add, just warning you about the duplicate model number... try this

 

     case 'new_product_preview':
// MODEL NO BOF
 $check_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " where products_model = '" . tep_db_input($products_model) . "'");
     $check_model = tep_db_fetch_array($check_products_query);
     if ($check_model['total'] > 0) {
       $error = true; 
       $messageStack->add(ENTRY_MODEL_ERROR, 'error');
    }
//MODEL NO EOF
// copy image only if modified
       $products_image = new upload('products_image');
       $products_image->set_destination(DIR_FS_CATALOG_IMAGES);
       if ($products_image->parse() && $products_image->save()) {
         $products_image_name = $products_image->filename;
       } else {
         $products_image_name = (isset($HTTP_POST_VARS['products_previous_image']) ? $HTTP_POST_VARS['products_previous_image'] : '');
       }
       break;

 

Let's see if this does what you want before we work on whether you want to actually prevent the addition or not.

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...