Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / Using products_id as Products Model

Using products_id as Products Model

Locked

Views: 2,169

Results 1 to 7 of 7
This thread is locked. New replies are disabled.
22 Mar 2009, 4:01 PM
#1
soki avatar

soki

New Zenner

Join Date:
Apr 2008
Location:
Athens
Posts:
85
Plugin Contributions:
0

Using products_id as Products Model

Hello Zeners!

I want my products getting as Products Model the products_id that zencart automatically generate.

Is a simple way to do that?

Kind regards :smile:

22 Mar 2009, 4:22 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Using products_id as Products Model

You could just use a quick UPDATE in the Tools ... Install SQL Patches ...

UPDATE products SET products_model= products_id;

That will change ALL products_model to match the products_id of ALL of your Products ...

NOTE: Backing up your database before doing something like this is always a good idea ...

You could also customize the code to do this when new Products are added to the database if you get tired of running the code manually ...

22 Mar 2009, 5:25 PM
#3
soki avatar

soki

New Zenner

Join Date:
Apr 2008
Location:
Athens
Posts:
85
Plugin Contributions:
0

Re: Using products_id as Products Model

Thanks Ajeh!

Please tell me in which file I must add this sql statement so do this automatically every time I add a new product?

:smartalec:

22 Mar 2009, 6:30 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Using products_id as Products Model

The SQL statement is just for a quick, global change of all products_model to match the products_id ...

To customize the code to do this when adding a New Product, you would need to customize the file:
/admin/includes/modules/update_products.php

NOTE: and you would need to customize any other product type with its own update module ...

and around line 86 you will see:

      ///////////////////////////////////////////////////////
      //// INSERT PRODUCT-TYPE-SPECIFIC *INSERTS* HERE //////

change to read:

// update products_model with products_id
      $sql_data_array = array( 'products_model' => (int)$products_id);
      zen_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");

      ///////////////////////////////////////////////////////
      //// INSERT PRODUCT-TYPE-SPECIFIC *INSERTS* HERE //////

This will add the new products_id as the products_model when adding new products ...

NOTE: even if you enter a products_model manually when adding a Product, this will override that ...

If you needed a different products_model you should be able to still edit the Product to change this manually ...

22 Mar 2009, 7:22 PM
#5
soki avatar

soki

New Zenner

Join Date:
Apr 2008
Location:
Athens
Posts:
85
Plugin Contributions:
0

Re: Using products_id as Products Model

Thanx Ajeh it worked on new products but not worked when I copy(duplicate) similar products changing the desctription a bit and then hit update.
Can this function works automatically when copying(duplicating) similar products?

Thanx again for your help!:blush:

22 Mar 2009, 7:29 PM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Using products_id as Products Model

I would have to customize the code in a number of places to manage everything that you need for this to work everywhere in relationship to maintaining the products_id and products_model match ...

You might try a search in the Admin using the Developers Tool Kit for:
products_model

and see if you can spot all of the places that this code might need to be changed ...

22 Mar 2009, 7:43 PM
#7
soki avatar

soki

New Zenner

Join Date:
Apr 2008
Location:
Athens
Posts:
85
Plugin Contributions:
0

Re: Using products_id as Products Model

Ok I found it!

In admin/includes/modules/copy_to_confirm.php

In about line 110
//FIX here

added the previous statement

// update products_model with products_id
      $sql_data_array = array( 'products_model' => (int)$products_id);
      zen_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");

and works also when I copy (duplicate) products!

Thanks again for your help! :clap: