Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Easy Populate & Multiple Categories


drfunk

Recommended Posts

Hi,

 

Thought I'd share something if anyone wanted to do this. If you want to populate ur products with easy populate and want certain products in other categories as well, then here's wat ya have to do.

 

Create a new field in easy populate (lets call it other_category). You can find out how to do this if you search the contributions support.

 

After this chunk of code:

 

if (isset($v_categories_id)){

//find out if this product is listed in the category given

$result_incategory = tep_db_query('SELECT

'.TABLE_PRODUCTS_TO_CATEGORIES.'.products_id,

'.TABLE_PRODUCTS_TO_CATEGORIES.'.categories_id

FROM

'.TABLE_PRODUCTS_TO_CATEGORIES.'

WHERE

'.TABLE_PRODUCTS_TO_CATEGORIES.'.products_id='.$v_products_id.' AND

'.TABLE_PRODUCTS_TO_CATEGORIES.'.categories_id='.$v_categories_id);

 

if (tep_db_num_rows($result_incategory) == 0) {

// nope, this is a new category for this product

$res1 = tep_db_query('INSERT INTO '.TABLE_PRODUCTS_TO_CATEGORIES.' (products_id, categories_id)

VALUES ("' . $v_products_id . '", "' . $v_categories_id . '")');

} else {

// already in this category, nothing to do!

}

}

 

Add this:

 

$sql2 = "SELECT ".TABLE_CATEGORIES_DESCRIPTION.".categories_id

 

FROM ".TABLE_CATEGORIES_DESCRIPTION."

WHERE

".TABLE_CATEGORIES_DESCRIPTION.".categories_name ='" . $v_other_category . "' AND

".TABLE_CATEGORIES_DESCRIPTION.".language_id = " . $epdlanguage_id ;

 

$result2 = tep_db_query($sql2);

$row2 = tep_db_fetch_array($result2);

 

if($row2['categories_id'] != '')

{

tep_db_query('INSERT INTO '.TABLE_PRODUCTS_TO_CATEGORIES.' (products_id, categories_id)

VALUES ("' . $v_products_id . '", "' .$row2['categories_id']. '")');

}

 

After all that, make sure you manually enter in all the categories first b4 populating.

 

Well, thats about it. Hope it helps some of you. If you can think of better ways to do this, please let me know.

I'm an Idiot !

Link to comment
Share on other sites

Yes, it will.

 

There was actually problems with the one I posted, use this one:

 

 

  //testing
   //this getst the categories ID
   $sql2 = "SELECT ".TABLE_CATEGORIES_DESCRIPTION.".categories_id
   
  	 FROM ".TABLE_CATEGORIES_DESCRIPTION."
  	 WHERE	
     ".TABLE_CATEGORIES_DESCRIPTION.".categories_name ='" . $v_other_category . "' AND
     ".TABLE_CATEGORIES_DESCRIPTION.".language_id = " . $epdlanguage_id;

   $result2 = tep_db_query($sql2);
   $link = 'db_link';
    	 global $$link;

   $row2 =  tep_db_fetch_array($result2);
   
   //this will make the link for the products to multiple categories.
   if($row2['categories_id'] != '')
   {	$yoyo = "INSERT INTO" . TABLE_PRODUCTS_TO_CATEGORIES. " (products_id, categories_id)
    	 VALUES ('" . $v_products_id. "','" . $row2['categories_id']. "')";
  	 
      if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
           error_log('QUERY ' . $yoyo . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
         }
     $yoyoyo = mysql_query($yoyo, $$link); 
      
      if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
          	 $result_error = mysql_error();
           error_log('RESULT ' . $yoyoyo . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
         }
  	 //original
  	 //tep_db_query('INSERT INTO '.TABLE_PRODUCTS_TO_CATEGORIES.' (products_id, categories_id)
    	 //VALUES ("' . $v_products_id . '", "' .$row2['categories_id']. '")');
   }

   //second part
   //I happen to need to do it twice so, this isnt needed depending on what you wanna do.
   $sql3 = "SELECT ".TABLE_CATEGORIES_DESCRIPTION.".categories_id
   
  	 FROM ".TABLE_CATEGORIES_DESCRIPTION."
  	 WHERE	
     ".TABLE_CATEGORIES_DESCRIPTION.".categories_name = '" . $v_other_category2 . "' AND
     ".TABLE_CATEGORIES_DESCRIPTION.".language_id = " . $epdlanguage_id;

   $result3 = tep_db_query($sql3);
   $row3 =  tep_db_fetch_array($result3);
   
   if($row3['categories_id'] != '')
   {
  	 $yoyoyo = "INSERT INTO" . TABLE_PRODUCTS_TO_CATEGORIES. " (products_id, categories_id)
    	 VALUES ('" . $v_products_id. "','" . $row3['categories_id']. "')";
  	 
      if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
           error_log('QUERY ' . $yoyoyo . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
         }
     $yoyoyoyo = mysql_query($yoyoyo, $$link); 
      
      if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
          	 $result_error = mysql_error();
           error_log('RESULT ' . $yoyoyoyo . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
         }
      //original
  	 //tep_db_query('INSERT INTO '.TABLE_PRODUCTS_TO_CATEGORIES.' (products_id, categories_id)
    	 //VALUES ("' . $v_products_id . '", "' .$row3['categories_id']. '")');
   }
   //end testing

 

Just another Reminder. Make sure your categories are already made first before you run easypoopulate with this code.

 

Hope it works for you.

I'm an Idiot !

Link to comment
Share on other sites

Sure,

 

I'll do that sometime within the next two weeks.

 

I didn't bother to make a contribution b/c I didn't think it was worth it since you really dont have to change much. Just have to add that chunk of code in where I say its suppose to go.

 

So you guys get it working?

I'm an Idiot !

Link to comment
Share on other sites

I haven't even tried yet...but when mibble jumped in, I figured he must have at least given it a cursury glance before asking you to post it into the main thread :) I will be trying it out tonight. I had to get something else working in my easypopulate.php before I could try your code out. It does work well for you eh?

Link to comment
Share on other sites

Ok, I've followed the instructions for adding a new field (btw, I've added several fields successfully in the past...) but I think because we're dealing with categories ?? that I have to add data different from what is in the instructions for adding fields...

 

I beg you...please, could you post the code to add in and where to put it? It think its only in like 4 or 5 places? Something like "After this: blah blah" "Add this: blah blah". This would help me tremendously. OR...could you post your easypopulate.php file (or email it to me) so I can find the changes myself and add it?

 

thanks a bunch for all your work!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...