Archive for the ‘Content Management’ Category

Zen Cart copying product_type_layout for a new product_type

Wednesday, November 24th, 2010

I have been working on a new site for Global Art Prints.  The site is an online shop selling Limited Edition prints, mainly by British artists.   I have customised a Zen Cart eCommerce installation to suit the new shop.  As part of the process I have needed to add a new product type, Product – Print, I need fields like colour and size that aren’t included in the Product – General type.

For the All product listing and New product listing pages the product_type_layout file determines which fields appear on the screen.  The simplest thing is to duplicate the existing product_type_layout entries for product_type = ‘1’  (Product – General), the copy can then be used as a base for the display of the new product_type.

So to save somebody some work I offer this mySQL statement which copies all the product_type_layout records for Product – General and creates a new version for Product – Print;

INSERT INTO product_type_layout 
  (configuration_title,
   configuration_key,
   configuration_value, 
   configuration_description,
   product_type_id,
   sort_order,
   last_modified,
   date_added,
   use_function,
   set_function)
SELECT
   configuration_title, 
   REPLACE(configuration_key,'PRODUCT_','PRODUCT_PRINT_'),   
   configuration_value, 
   configuration_description,
   '6',                                                      
   sort_order,
   now(),
   now(),
   use_function,
   set_function 
FROM product_type_layout
  WHERE product_type_id = '1';          

The new records are a copy of the existing Product – General records except;

  • configuration_id isn’t explicitly set, this will be handled by mySQL’s auto_increment.
  • The configuration_key text PRODUCT_ is replaced by PRODUCT_PRINT – we can’t have duplicate configuration_key values.
  • The new product_type_id = ‘6’ which is the value for my new Product – Print type.
  • The last_modified and date_added fields are set to the current date/time.

I ran this enquiry using phpMyAdmin in my test environment but I used the Tools/Install SQL Patches option in Zen Cart’s admin area to apply the same change to the live site.