Skip to content

Instantly share code, notes, and snippets.

@lsauer
Forked from timbroder/gist:1209944
Created September 11, 2011 19:45
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 lsauer/1210023 to your computer and use it in GitHub Desktop.
Save lsauer/1210023 to your computer and use it in GitHub Desktop.
insert update url rewrite
#INSERT INTO `core_url_rewrite` (`store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`)
SELECT 1 AS `store_id`,
`sub`.`category_id`,
`sub`.`entity_id` AS `product_id`,
CONCAT('product', '/', `entity_id`, '/', `category_id`) AS `id_path`,
`value` AS `request_path`,
CONCAT('catalog/product/view/id/', `entity_id`, '/category/', `category_id`) AS `target_path`,
1 AS `is_system`
FROM
(SELECT
'/' AS `path`,
#`pv`.`value`,
CONCAT(REPLACE(`cpe`.`sku`, 'US ', 'used-'), '.html') as `value`,
`pv`.`entity_id`,
`cpe`.`sku`,
`ccp`.`category_id`
FROM `catalog_product_entity_varchar` AS `pv`
INNER JOIN `catalog_category_product` AS `ccp`
ON `ccp`.`product_id` = `pv`.`entity_id` AND ccp.category_id != 2
INNER JOIN `catalog_product_entity` AS `cpe`
ON `cpe`.`entity_id` = `pv`.`entity_id`
LEFT JOIN `catalog_category_entity_varchar` AS `cv`
ON `cv`.`entity_id` = `ccp`.`category_id` AND `cv`.`attribute_id` = 49
WHERE (`pv`.`attribute_id` = 87)
GROUP BY `path`,`cv`.`value`)
AS `sub`
#ON DUPLICATE KEY
#UPDATE `store_id` = VALUES(`store_id`), `category_id` = VALUES(`category_id`), `product_id` = VALUES(`product_id`), `id_path` = VALUES(`id_path`), `request_path` = VALUES(`request_path`), `target_path` = VALUES(`target_path`), `is_system` = VALUES(`is_system`)
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment