1. CREATE FETURES
  2. DEFINE FITURE VALUE
  3. CREATE PRODUCT
  4. ASSIGN FEETURE TO PRODUC

TIPS: Use SQL variables

Query example:

This query assume that you are not using custom value but predefined feature and predefined feature value.
If your value is not in database, then you can create it through admin panel or add insert statement for PREFIX_feature_value and PREFIX_feature_value_lang.

INSERT INTO ps_feature_product (id_feature, id_product, id_feature_value) VALUES ('4', '4797', '449');

Adding new features with SQL:

  1. INSERT INTO PREFIX_feature (position) VALUES ((SELECT MAX(position) FROM PREFIX_feature) + 1);
  2. @ID := SELECT LAST_INSERT_ID() — works only with single insert
  3. INSERT INTO PREFIX_feature_lang id_feature
  • remember to replace PREFIX_feature with your prefix like ps_feature

Tabel structure

/* Position of each feature */

CREATE TABLE `PREFIX_feature` (
  `id_feature` int(10) unsigned NOT NULL auto_increment,
  `position` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`id_feature`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4 COLLATION;

 

/* Localized feature info */

CREATE TABLE `PREFIX_feature_lang` (
  `id_feature` int(10) unsigned NOT NULL,
  `id_lang` int(10) unsigned NOT NULL,
  `name` varchar(128) DEFAULT NULL,
  PRIMARY KEY (`id_feature`, `id_lang`),
  KEY (`id_lang`, `name`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4 COLLATION;

 

/* Association between a feature and a product */

CREATE TABLE `PREFIX_feature_product` (
  `id_feature` int(10) unsigned NOT NULL,
  `id_product` int(10) unsigned NOT NULL,
  `id_feature_value` int(10) unsigned NOT NULL,
  PRIMARY KEY (
    `id_feature`, `id_product`, `id_feature_value`
  ),
  KEY `id_feature_value` (`id_feature_value`),
  KEY `id_product` (`id_product`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4 COLLATION;

 

/* Various choice associated with a feature */

CREATE TABLE `PREFIX_feature_value` (
  `id_feature_value` int(10) unsigned NOT NULL auto_increment,
  `id_feature` int(10) unsigned NOT NULL,
  `custom` tinyint(3) unsigned DEFAULT NULL,
  PRIMARY KEY (`id_feature_value`),
  KEY `feature` (`id_feature`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4 COLLATION;

 

/* Localized feature choice */

CREATE TABLE `PREFIX_feature_value_lang` (
  `id_feature_value` int(10) unsigned NOT NULL,
  `id_lang` int(10) unsigned NOT NULL,
  `value` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id_feature_value`, `id_lang`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4 COLLATION;

PrestaShop database uses naming convection. Lets search the database for “features” phrase related tables.

SELECT TABLE_NAME, ENGINE, TABLE_COLLATION, CREATE_OPTIONS, TEMPORARY 
FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_NAME LIKE '%feature%' GROUP BY TABLE_NAME;

Database structure:
https://github.com/PrestaShop/PrestaShop/blob/1.7.7.x/install-dev/data/db_structure.sql
search for “PREFIX_feature_product”

0
Would love your thoughts, please comment.x
()
x