Created
April 25, 2018 02:26
-
-
Save debuss/87608854dc54372d7227d9ff5715e847 to your computer and use it in GitHub Desktop.
This query generate references (SKU) for your products and combinations on PrestaShop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Set references on parent products | |
UPDATE `ps_product` p | |
SET p.`reference` = REPLACE(REPLACE(LOWER(CONCAT_WS( | |
"_", | |
LEFT((SELECT CONVERT(`name` USING ascii) FROM `ps_product_lang` pl WHERE pl.`id_product` = p.`id_product` LIMIT 1), 10), | |
p.`id_product`, | |
"0" | |
)), "?", ""), " ", "") | |
WHERE p.`reference` IS NULL | |
OR p.`reference` = ""; | |
-- Set references on child products | |
UPDATE `ps_product_attribute` pa | |
SET pa.`reference` = REPLACE(REPLACE(LOWER(CONCAT_WS( | |
"_", | |
LEFT((SELECT CONVERT(`name` USING ascii) FROM `ps_product_lang` pl WHERE pl.`id_product` = pa.`id_product` LIMIT 1), 10), | |
pa.`id_product`, | |
pa.`id_product_attribute` | |
)), "?", ""), " ", "") | |
WHERE pa.`reference` IS NULL | |
OR pa.`reference` = ""; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi
Hi
I was studying your query, could you give me a hand to modify it, so that the reference is thus "ProductName-Nomeattribute"
best regards
Ilario