这段时间要对magento上的站做些数据处理,以前上的站有些数据不合理,要增加custom option属性,本人实在不想看看程序了,再者用程序写的花一段时间的,就分析了一下magento数据库的一些表,打算用存储过程批量加。其中也遇到问题了,解决如下:
1.找出需要操作的表:
-
catalog_product_option;
-
catalog_product_option_title;
-
catalog_product_option_price;
-
catalog_product_option_type_title;
-
catalog_product_option_type_value;
-
catalog_product_option_type_price;
-
catalog_product_entity
2. 根据catalog_product_entity求出sku或id;
3. 编写存储过程根据custom option类型不一样有所区别:
如 field类型:
delimiter //
drop procedure bust//
create procedure bust(p_sku varchar(255))
BEGIN
DECLARE v_entity_id INT;
DECLARE v_option_id INT;
DECLARE v_option_type_id INT;
SELECT entity_id INTO v_entity_id FROM catalog_product_entity WHERE sku = p_sku;
select v_entity_id;
INSERT INTO catalog_product_option (product_id, type, is_require, sku, max_characters, file_extension, image_size_x, image_size_y, sort_order) VALUES
(v_entity_id, 'field', 1, '', NULL, NULL, 0, 0, 3);
SELECT max(option_id) INTO v_option_id FROM catalog_product_option WHERE product_id = v_entity_id;
select v_option_id;
INSERT INTO catalog_product_option_title (option_id, store_id, title) VALUES
(v_option_id, 0, 'Bust');
UPDATE catalog_product_entity SET has_options = '1' WHERE catalog_product_entity.entity_id =v_entity_id;
END;
如 checkbox类型:
delimiter //
drop procedure customize//
create procedure customize(p_sku varchar(255))
BEGIN
DECLARE v_entity_id INT;
DECLARE v_option_id INT;
DECLARE v_option_type_id INT;
SELECT entity_id INTO v_entity_id FROM catalog_product_entity WHERE sku = p_sku;
select v_entity_id;
INSERT INTO catalog_product_option (product_id, type, is_require, sku, max_characters, file_extension, image_size_x, image_size_y, sort_order) VALUES
(v_entity_id, 'checkbox', 0, '', NULL, NULL, 0, 0, 5);
SELECT max(option_id) INTO v_option_id FROM catalog_product_option WHERE product_id = v_entity_id;
select v_option_id;
INSERT INTO catalog_product_option_title (option_id, store_id, title) VALUES
(v_option_id, 0, 'custom size(inch)');
INSERT INTO catalog_product_option_type_value (option_id, sku, sort_order) VALUES
(v_option_id, '', 0);
SELECT max(option_type_id) INTO v_option_type_id FROM catalog_product_option_type_value;
select v_option_type_id;
INSERT INTO catalog_product_option_type_price (option_type_id, store_id, price, price_type) VALUES
(v_option_type_id, 0, '19.99', 'fixed');
INSERT INTO catalog_product_option_type_title (option_type_id, store_id, title) VALUES
(v_option_type_id, 0, 'custom size(inch)');
UPDATE catalog_product_entity SET has_options = '1' WHERE catalog_product_entity.entity_id =v_entity_id;
END;
至于其它类型自己类推写就可以了。
4. 通过程序批量调用3写的存储过程就行了。
这个方法还没仔细优化过,个人觉得还有更好的方法实现,由于时间关系,没具体想,实现的达到的目的就ok了!打完收工
(责任编辑:好模板) |