2011-03-10 4 views
1

온라인 상점을 만들고 있는데 문제가 있습니다. 직접 가격 (예 : HTC Touch 2 스마트 폰 : $ 299.00)의 제품을 갖지만 동시에 사양에 따라 조합 가격을 가진 제품을 갖게됩니다 :웹샵을위한 MySQL 데이터베이스 구조

이 이미지에서 나는 여러 가격 제품에 대한 확인이 될 것이라고 생각 데이터베이스 다이어그램 : database diagram

주요 문제 : 이것은 인터넷 쇼핑몰이기 때문에 , 사람들이 장바구니에 상품을 담은 것입니다. 나는 장바구니에 넣은 품목이 같은 테이블에 있어야한다고 생각한다. (우리의 경우에는 가격이 저장되기 때문에 [combinations] 테이블이 될 것이다.) 여기

은 더 명확하게하기 위해,이 테이블에 대한 일부 데이터입니다

[products]

productid | productName 
1   | Nike T-Shirt 
2   | HTC Touch 2 Smartphone 

[specifications]

specId | productId | specName 
1  | 1   | Size 
2  | 1   | Color 

[specvalues]

specValueId | specId | svValue 
1    | 1  | L 
2    | 1  | XL 
3    | 2  | white 
4    | 2  | blue 
5    | 2  | red 

[combinations] (카트에 항목)

[combinationParts]

nmid | combinationId | specValueId 
1  | 1    | 1 
2  | 1    | 3 
3  | 2    | 2 
4  | 2    | 3 
5  | 3    | 1 
1  | 3    | 4 
2  | 4    | 2 
3  | 4    | 4 
4  | 5    | 2 
5  | 5    | 5 

combinationId | price | description 
1    | 10  | White L Nike T-Shirt 
2    | 15  | White XL Nike T-Shirt 
3    | 11  | Blue L Nike T-Shirt 
4    | 16  | Blue XL Nike T-Shirt 
5    | 18  | Red XL Nike T-Shirt 
나는 나의 그림 및 데이터베이스 인구 : 이해가 않습니다 바랍니다.

따라서 단일 가격 제품 (HTC Touch 2 Smartphone)을 여러 가격 제품과 마찬가지로 장바구니에 추가 할 수있는 방법은 무엇입니까?

답변

0

당신이 실제로 좋은 일을 .. OpenCarts 데이터베이스를 살펴 할 수 있습니다 ... 기본적으로

:

를위한 테이블 만들기 : 제품 제품 옵션 (당신 ' 제품 테이블 '각각의 제품이 나열 될

)'과에서 가격 이 '제품 옵션에'사양 '테이블, 당신은 본질적으로 다른 목록'spcifications ') 제품 옵션 값 (당신의'specvalues 제품 ...
제품 옵션 값 테이블에는 실제 옵션과 기본 가격 (+/-)의 변경 사항이 나열되어 있습니다 ...

완료된 주문을 저장하려면 OpenCart가 본질적으로 동일한 테이블을 가지고 있어야합니다. 주문 id가 연관된)

Recetly 토너먼트의 플레이어 등록을 처리하기 위해 장바구니 기능을 리핑했습니다 ...$ (25) 'product_option'단순히 값이 'product_option_value'에 저장되어있는 '스펙'을 '등록 형'의 경우/"등록 유형"

가 나열 -

기본 '제품은'선수 등록입니다 테이블 ... 그들은 & 놀이로 등록 할 수 있습니다 (& 놀이는 minigames로 들어갑니다) 지불은 가격에 변화없이 단지 기본 옵션입니다 ... 유료 앤 플레이는 $ 15를 가격에 추가합니다 $ 40 합계)

쉽게 여러 개의 "Produc t_options "및"product_option_value "세트가 제품에 ... 각각의 제품을 더하거나 뺍니다 ...

스크립트 쪽에서는 제품을 사용하여 어레이를 쿼리하고 빌드하는 데 몇 개의 루프 만 걸립니다. 당신이 말한 경우 각 제품의 옵션 배열

'product_option_value'테이블의 하위 배열과 같은 제품의 하위 배열과 같은 제품 옵션을 배열, 제품 옵션 값은

-- 
-- Table structure for table `product` 
-- 

CREATE TABLE IF NOT EXISTS `product` (
    `product_id` int(11) NOT NULL auto_increment, 
    `site_id` int(11) NOT NULL, 
    `name` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL, 
    `description` text character set utf8 collate utf8_unicode_ci NOT NULL, 
    `price` decimal(15,2) NOT NULL default '0.00', 
    `date_available` date NOT NULL, 
    `date_unavailable` date NOT NULL, 
    `status` int(1) NOT NULL default '0', 
    `date_added` datetime NOT NULL default '0000-00-00 00:00:00', 
    `date_modified` datetime NOT NULL default '0000-00-00 00:00:00', 
    PRIMARY KEY (`product_id`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=2 ; 

-- 
-- Dumping data for table `product` 
-- 

INSERT INTO `product` (`product_id`, `site_id`, `name`, `description`, `price`, `date_available`, `date_unavailable`, `status`, `date_added`, `date_modified`) VALUES 
(1, 2, 'Player Registration', 'This year we have two options: Pay or Pay &amp; Play.<br />Pay &amp; Play allows you to enroll in the Flights Minigames for the weekend (Master''s Marks and Flights Doubles) and gives you twenty dollars worth of prize raffles. <br />Pay &amp; Play is a $60.00 value and is only avalible during pre-registration.', 25.00, '2011-03-01', '2011-03-31', 1, '2011-03-01 00:00:00', '2011-03-01 00:00:00'); 

-- -------------------------------------------------------- 

-- 
-- Table structure for table `product_option` 
-- 

CREATE TABLE IF NOT EXISTS `product_option` (
    `product_option_id` int(11) NOT NULL auto_increment, 
    `product_id` int(11) NOT NULL, 
    `sort_order` int(3) NOT NULL default '0', 
    `name` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL, 
    PRIMARY KEY (`product_option_id`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=2 ; 

-- 
-- Dumping data for table `product_option` 
-- 

INSERT INTO `product_option` (`product_option_id`, `product_id`, `sort_order`, `name`) VALUES 
(1, 1, 1, 'Registration Type'); 

-- -------------------------------------------------------- 

-- 
-- Table structure for table `product_option_value` 
-- 

CREATE TABLE IF NOT EXISTS `product_option_value` (
    `product_option_value_id` int(11) NOT NULL auto_increment, 
    `product_option_id` int(11) NOT NULL, 
    `product_id` int(11) NOT NULL, 
    `price` decimal(15,2) NOT NULL, 
    `prefix` char(1) collate utf8_bin NOT NULL, 
    `sort_order` int(3) NOT NULL, 
    `name` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL, 
    PRIMARY KEY (`product_option_value_id`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=3 ; 

-- 
-- Dumping data for table `product_option_value` 
-- 

INSERT INTO `product_option_value` (`product_option_value_id`, `product_option_id`, `product_id`, `price`, `prefix`, `sort_order`, `name`) VALUES 
(1, 1, 1, 15.00, '+', 1, 'Pay &amp; Play'), 
(2, 1, 1, 0.00, '', 2, 'Pay'); 
2

당신은 머리에 못을 명중 '장바구니에 넣은 품목은 같은 테이블에 있어야한다고 생각합니다.'

HTC 전화는 조합 표에 하나의 조합으로 존재해야합니다.

---------------+-------------+------------------------ 
combinationId |  price | description 
---------------+-------------+------------------------ 
6    |  299  | Base Model 
---------------+-------------+------------------------ 

이것은 imediate 문제를 해결하고, 어떤 단점이 없습니다 : 위에서 귀하의 예제를 사용하여, 같은 조합 테이블에 다른 항목을 삽입합니다. 또한 상점이 성장하고 HTC가 다른 가격대의 새로운 모델을 출시 할 가능성이 높아지고있는 경우 이미 데이터베이스 구조가 적합합니다. 예를 들어 제 생각에 가장 단순한 솔루션은 하나의 specvalues ​​레코드와 스마트 폰을 하나의 사양 기록을 제공하는 것입니다

---------------+-------------+------------------------ 
combinationId |  price | description 
---------------+-------------+------------------------ 
6    |  299  | Base Model 
7    |  349  | Exclusive Edition 
---------------+-------------+------------------------ 
0

를 들어

. 그렇게하면 모든 유형의 제품 레코드에 대해 구조를 그대로 유지할 수 있습니다. 옵션이 하나 뿐인 경우 productview에 선택 가능한 옵션을 표시하지 마십시오.