CREATE VIEW `sivir_products_list` AS
SELECT `product`.`relative` AS `relative`,
`product`.`users_sid` AS `users_sid`,
`product`.`global_branch_office_id` AS `global_branch_office_id`,
`product`.`fullname` AS `fullname`,
`product`.`description` AS `description`,
`product`.`code` AS `code`,
`product`.`category_id` AS `category_id`,
`product`.`subcategory_id` AS `subcategory_id`,
`product`.`brand_id` AS `brand_id`,
`product`.`barcode` AS `barcode`,
`product`.`enabled` AS `enabled`,
`product`.`status` AS `status`,
`product`.`created_at` AS `created_at`,
`product`.`updated_at` AS `updated_at`,
`price`.`price` AS `price`,
`price`.`currency_id` AS `currency_id`,
`currency`.`code` AS `currency`,
`category`.`label` AS `category`,
`subcategory`.`label` AS `subcategory`,
`brand`.`label` AS `brand`,
`stock`.`quantity` AS `quantity`,
`stock`.`measurement_id` AS `measurement_id`,
`measurement`.`label` AS `measurement`
FROM `core_sivir`.`sivir_products` AS `product`
join `core_sivir`.`sivir_products_price` AS `price`
join `core_sivir`.`core_sivir_currency` AS `currency`
join `core_sivir`.`sivir_catalog_items` AS `category`
join `core_sivir`.`sivir_catalog_items` AS `subcategory`
join `core_sivir`.`sivir_catalog_items` AS `brand`
join `core_sivir`.`sivir_products_stock` AS `stock`
join `core_sivir`.`sivir_catalog_items` AS `measurement`
WHERE ((convert(`product`.`relative` using utf8) = `price`.`product_id`)
       and (`product`.`relative` = `stock`.`product_id`)
       and (`price`.`currency_id` = `currency`.`id`)
       and (`product`.`category_id` = `category`.`value`)
       and (`category`.`catalog_code` = 'CATEGORY')
       and (`category`.`catalog_code_dep` = 0)
       and (`category`.`catalog_id_dep` = 0)
       and (`category`.`global_branch_office_id` = `product`.`global_branch_office_id`)
       and (`product`.`subcategory_id` = `subcategory`.`value`)
       and (`subcategory`.`catalog_code` = 'CATEGORY')
       and (`subcategory`.`catalog_code_dep` = 'CATEGORY')
       and (`subcategory`.`catalog_id_dep` = `product`.`category_id`)
       and (`subcategory`.`global_branch_office_id` = `product`.`global_branch_office_id`)
       and (`product`.`brand_id` = `brand`.`value`)
       and (`brand`.`catalog_code` = 'BRAND')
       and (`brand`.`catalog_code_dep` = 0)
       and (`brand`.`catalog_id_dep` = 0)
       and (`brand`.`global_branch_office_id` = `product`.`global_branch_office_id`)
       and (`stock`.`measurement_id` = `measurement`.`value`)
       and (`measurement`.`catalog_code` = 'MEASUREMENT')
       and (`measurement`.`catalog_code_dep` = 0)
       and (`measurement`.`catalog_id_dep` = 0)
       and (`measurement`.`global_branch_office_id` = `product`.`global_branch_office_id`)
      )

