0

Sometimes I have magento installations where my coleagues do edit files in ./vendor folder. Therefore, using magento's seeder will require extra dependencies and may break the ./vendor folder. As a result, I cannot use the existing seeder.

But instead I can make a seperate scrips that manipulates db directly. So what tables do I need in order to seed test products directly?

1 Answer 1

2

Get all Simple products (sku, qty, stock_status) :

 select 
  catalog_product_entity.sku, 
  cataloginventory_stock_item.qty,
  cataloginventory_stock_status.stock_status 
from        
  catalog_product_entity join cataloginventory_stock_item on
       catalog_product_entity.entity_id=cataloginventory_stock_item.product_id 
join
 cataloginventory_stock_status on catalog_product_entity.entity_id =
             cataloginventory_stock_status.product_id
where type_id = "simple";
1. insert new product
INSERT INTO `catalog_product_entity` (`entity_id`, `attribute_set_id`, `type_id`, `sku`, `has_options`, `required_options`, `created_at`, `updated_at`) VALUES (NULL, '4', 'simple', 'my-sku-test', '0', '0', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
[get entity id of new product]

2. Set status of new product using entity_id
INSERT INTO `catalog_product_entity_int` (`value_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES (NULL, '97', '1', '17', '1');

3. Set visibility of product using entity_id
INSERT INTO `catalog_product_entity_int` (`value_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES (NULL, '99', '0', '17', '4')

4. Set tax_class_id of product
INSERT INTO `catalog_product_entity_int` (`value_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES (NULL, '134', '0', '17', '0')

5. Set filter_price_range of product
INSERT INTO `catalog_product_entity_decimal` (`value_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES (NULL, '77', '0', '17', '100');

6. Set weight of product
INSERT INTO `catalog_product_entity_decimal` (`value_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES (NULL, '82', '0', '17', '10')

7. Set quantity of product
INSERT INTO `cataloginventory_stock_item` (`item_id`, `product_id`, `stock_id`, `qty`, `min_qty`, `use_config_min_qty`, `is_qty_decimal`, `backorders`, `use_config_backorders`, `min_sale_qty`, `use_config_min_sale_qty`, `max_sale_qty`, `use_config_max_sale_qty`, `is_in_stock`, `low_stock_date`, `notify_stock_qty`, `use_config_notify_stock_qty`, `manage_stock`, `use_config_manage_stock`, `stock_status_changed_auto`, `use_config_qty_increments`, `qty_increments`, `use_config_enable_qty_inc`, `enable_qty_increments`, `is_decimal_divided`, `website_id`) VALUES (NULL, '17', '1', '1000', '0.0000', '1', '0', '0', '1', '1.0000', '1', '0.0000', '1', '0', NULL, NULL, '1', '0', '1', '0', '1', '0.0000', '1', '0', '0', '0');

8. Set name of product
INSERT INTO `catalog_product_entity_varchar` (`value_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES (NULL, '73', '0', '17', 'my-sku-test');

9. Set url of product
INSERT INTO `catalog_product_entity_varchar` (`value_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES (NULL, '121', '0', '17', 'my-sku-test');
2
  • Seeding would be to insert, not to query.
    – MackieeE
    Oct 3, 2023 at 11:44
  • check my updated answer Oct 3, 2023 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.