Is there an SQL command to add an attribute to all items in the store in bulk?
Printable View
Is there an SQL command to add an attribute to all items in the store in bulk?
Is this a brand-new attribute that isn't currently associated with any product?
Correct
It's going to be easier to create a one-time-run PHP script. Take this template, changing 33 to the options_id and 44 to the options_values_id of the to-be-inserted attribute and saving the script in the root directory of your site (let's pretend it's add_attributes.php):
Then on your browser's command line, enter https://mysite.com/add_attributes.php ... after you've made a database backup!Code:<?php
require 'includes/application_top.php';
$products = $db->Execute('SELECT products_id FROM ' . TABLE_PRODUCTS);
$sql_template =
'INSERT INTO ' . TABLE_PRODUCTS_ATTRIBUTES . '
(products_id, options_id, options_values_id)
VALUES
(%u, 33, 44)';
foreach ($products as $next_product) {
$sql = sprintf($sql_template, (int)$next_product['products_id']);
$db->Execute($sql);
}
require DIR_WS_INCLUDES . 'application_bottom.php';
Once run, make sure that the add_attributes.php file is deleted from the site.
Oh! Interesting! Thankyou!