5

There is a set of products in Drupal Commerce. How do I programmatically create a view that would select products for a particular field?

4
  • possible duplicate of Guidelines on customisation options when using hook_views_default_views?
    – Mołot
    Commented Jun 20, 2013 at 6:57
  • 1
    I don't think they are duplicates. The referenced question is asking about hook_views_default_views() for altering an existing view whereas this Q (seems to be) about creating a View programatically from scratch.
    – Chapabu
    Commented Jun 20, 2013 at 8:28
  • @Chapabu I trust if I'm mistaken people will vote for this one to stay.
    – Mołot
    Commented Jun 20, 2013 at 8:41
  • Not sure OP will return 8 months later and edit this post for better clarification. But it sounds like she was looking for some contextual filter stuff. Not to create a view object.
    – AKS
    Commented Jun 21, 2013 at 4:02

1 Answer 1

4

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.

3
  • 2
    Why did you just repeat my answer?
    – ram4nd
    Commented Jan 28, 2016 at 8:48
  • 2
    @ram4nd not quite repeat. Your answer lacked (and still lack) detailed info where to find export, and was poorly written (edited months after I posted mine).
    – Mołot
    Commented Jan 28, 2016 at 9:00
  • That's usually where adding a comment comes in. Usually you only post another answer if there's something fundamentally different about what you're saying.
    – Bratchley
    Commented Jun 1, 2017 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.