Skip to content

Instantly share code, notes, and snippets.

@akshaysasidrn
Last active June 26, 2017 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akshaysasidrn/a477e0173c724e94a2a384cdbe5374cd to your computer and use it in GitHub Desktop.
Save akshaysasidrn/a477e0173c724e94a2a384cdbe5374cd to your computer and use it in GitHub Desktop.
category_sku_mapping
require 'roo'
sheet = Roo::Spreadsheet.open("../../../../../tmp/missing_mapping.xlsx", clean: true)
headers = sheet.row(1)
mappings = []
sheet.each(sku: headers[0], category: headers[1], sku_type: headers[2]) do |hash|
mappings << hash
end
mappings.shift
invalid = []
def update_missing_label_category(mappings, invalid = [])
mappings.each do |mapping|
begin
Variant.connection.select_sp("CALL update_category_sku_type('#{mapping[:sku]}', '#{mapping[:category]}', '#{mapping[:sku_type]}')")
rescue => e
invalid << [mapping, e.message]
end
end
end
DROP PROCEDURE IF EXISTS update_category_sku_type;
CREATE PROCEDURE update_category_sku_type(IN skustr MEDIUMTEXT, IN category MEDIUMTEXT, IN skutype MEDIUMTEXT)
BEGIN
SET @skuparam = QUOTE(CONCAT(skustr,"%"));
SET @categoryparam = QUOTE(category);
SET @skutypeparam = QUOTE(skutype);
SET @sku_update_statement = CONCAT('UPDATE variants v JOIN products p ON v.product_id = p.id SET v.sku_type = ',@skutypeparam,', p.category_id = ( SELECT id FROM propertymasters where value = ',@categoryparam,' and ptype = \'category\' ) WHERE sku LIKE ',@skuparam,';');
PREPARE sku_update_statement FROM @sku_update_statement;
EXECUTE sku_update_statement;
DEALLOCATE PREPARE sku_update_statement;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment