There is a set of products in Drupal Commerce. How do I programmatically create a view that would select products for a particular field?
- Create your view the regular way (views export creates the code).
- Define your view API version and path for files that include view hooks by defining
- paste in
hook_views_default_views()the code you obtained in the first point.
See Creating views programmatically in Drupal 7 for more details.
The classic way is to create it manually, via UI, then click "export" (path like http://example.org/admin/structure/views/view/default_demo/export), and wrap resulting code into a module using hook_views_default_views(), maybe fine-tuning details.