Sku similar to Taobao

first of all, I found a lot of database design on Baidu, it can be said that there are different opinions! I see an intermediate table is designed like this, commodity ID sku attributes, unit price inventory, see that the intermediate attributes store json and then confused, please tell the gods what operation can throw these attributes and values together, and all stuffed under the specified goods?


about the concept of SKU, Google should first understand that
sku is made up of attribute and specifications, and attribute specifications need to be independent of each other. In order to avoid future business expansion, actually one attribute is linked to another specification attribute is a sku, for example:

: :
: :xl
: :xxl

then it has two more sku, (red + xl) (red + xxl)

here is my datasheet design

Commodity list

CREATE TABLE `product` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
  `category_id` int(11) NOT NULL COMMENT '',
  `mer_id` int(11) NOT NULL COMMENT '',
  `type_id` tinyint(4) NOT NULL COMMENT '',
  `sketch` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `intro` text COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
  `keywords` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `marque` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
  `barcode` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
  `brand_id` int(11) NOT NULL COMMENT '',
  `virtual` int(11) NOT NULL DEFAULT '0' COMMENT '',
  `price` decimal(8,2) NOT NULL COMMENT '',
  `market_price` decimal(8,2) NOT NULL COMMENT '',
  `integral` int(11) NOT NULL DEFAULT '0' COMMENT '',
  `stock` int(11) NOT NULL COMMENT '',
  `warning_stock` int(11) NOT NULL COMMENT '',
  `picture_url` varchar(125) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
  `status` tinyint(4) NOT NULL COMMENT ' -1=>,1=>,2=>,0=>',
  `is_package` enum('0','1') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '0' COMMENT '',
  `is_integral` enum('0','1') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '0' COMMENT '',
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=136 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

sku

CREATE TABLE `product_sku` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `product_id` int(11) NOT NULL COMMENT '',
  `name` varchar(125) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'sku',
  `img` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `price` decimal(8,2) NOT NULL COMMENT '',
  `stock` int(11) NOT NULL DEFAULT '0' COMMENT '',
  `code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `barcode` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  PRIMARY KEY (`id`),
  KEY `product_sku_name_product_id_index` (`name`,`product_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1125 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Specification sheet

CREATE TABLE `product_attribute` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `category_id` int(11) NOT NULL COMMENT '',
  `name` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
  `sort` int(11) NOT NULL DEFAULT '999' COMMENT '',
  PRIMARY KEY (`id`),
  KEY `product_attribute_category_id_name_index` (`category_id`,`name`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

property sheet

CREATE TABLE `product_attribute_option` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(125) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
  `attr_id` int(11) NOT NULL COMMENT '',
  `sort` int(11) NOT NULL DEFAULT '999' COMMENT '',
  PRIMARY KEY (`id`),
  KEY `product_attribute_option_name_attr_id_index` (`name`,`attr_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Table where the specification attribute is bound to SKU

CREATE TABLE `product_attribute_and_option` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `sku_id` int(11) NOT NULL COMMENT 'sku',
  `option_id` int(11) NOT NULL DEFAULT '0' COMMENT '',
  `attribute_id` int(11) NOT NULL COMMENT '',
  `sort` int(11) NOT NULL DEFAULT '999' COMMENT '',
  `supplier_option_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `product_attribute_and_option_sku_id_option_id_attribute_id_index` (`sku_id`,`option_id`,`attribute_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4819 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

json_encode learn about

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36974-4ec8e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36974-4ec8e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?