Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cergey-obr/5c62b1cc584af6cc06d964538a024d23 to your computer and use it in GitHub Desktop.
Save cergey-obr/5c62b1cc584af6cc06d964538a024d23 to your computer and use it in GitHub Desktop.
SELECT `main_table`.*,
`default_option_title`.`title` AS `default_title`,
`store_option_title`.`title` AS `store_title`,
IF(store_option_title.title IS NULL, default_option_title.title,
store_option_title.title) AS `title`,
`default_option_price`.`price` AS `default_price`,
`default_option_price`.`price_type` AS `default_price_type`,
`store_option_price`.`price` AS `store_price`,
`store_option_price`.`price_type` AS `store_price_type`,
IF(store_option_price.price IS NULL, default_option_price.price,
store_option_price.price) AS `price`,
IF(store_option_price.price_type IS NULL, default_option_price.price_type,
store_option_price.price_type) AS `price_type`
FROM `catalog_product_option` AS `main_table`
INNER JOIN `aitoc_catalog_product_option2template` AS `option2tpl`
ON option2tpl.option_id = main_table.option_id
INNER JOIN `catalog_product_option_title` AS `default_option_title`
ON default_option_title.option_id = main_table.option_id
LEFT JOIN `catalog_product_option_title` AS `store_option_title`
ON store_option_title.option_id = main_table.option_id AND store_option_title.store_id = '1'
LEFT JOIN `catalog_product_option_price` AS `default_option_price`
ON default_option_price.option_id = main_table.option_id AND default_option_price.store_id = 0
LEFT JOIN `catalog_product_option_price` AS `store_option_price`
ON store_option_price.option_id = main_table.option_id AND store_option_price.store_id = '1'
WHERE (`option2tpl`.`template_id` IN (11))
AND (`product_id` = '0')
AND (default_option_title.store_id = 0)
AND (main_table.sku != 'anti-fog')
ORDER BY FIELD(option2tpl.template_id, 11) DESC, sort_order ASC, title ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment