Vote up!
Vote down!

How to limit the variations shown to a user based on custom conditions?

I'm looking to create an ordering system for a company with multiple stores (physical locations).

  • There are multiple products, and each one could have a different price at each store.
  • The store for the order is selected based on the user's location.
  • The user's entire order must be placed with one store (i.e. they can't buy one item from one store and another item from a different store).

I'm thinking that I should create a content type for stores. I'd then create a field on the product variation that uses Entity Reference to point at the proper store node. My plan would be to create a page where the user can select their store before they start adding items to the cart. I'd then want to only show the product variation associated with their selected store.

My questions...

  • First, since I haven't used Drupal Commerce before... Does this make sense?
  • I was planning on saving the selected store in SESSION, but is there a solution that fits with DC better? Can I save it in the cart somehow before they start shopping?
  • How can I disable / remove the variations not associated with the selected store from the product display? Are there hooks that I can use?

If it helps, I'm an experienced Drupal developer, so I'm comfortable using hooks and creating custom code / modules as needed.

Asked by: jrb
on January 25, 2013

2 Answers

Vote up!
Vote down!

is this required for anonymous users? if so, that's tricky. if it were me, I'd try to find some way to get the user to choose their closest store... it can be a splash page (which would not solve people landing on other pages from search engine) or it could be a modal dialog that pops up after the user has been on the site for more than say three minutes asking their location. anyway, once i had their location i would try to use contextual filters in the url for that session. tough question without really knowing more. i am just throwing some ideas out there. but my main question is if this is an ecommerce shop, why does physical store matter in the first place? shouldn't they be able to have access to whatever products they want????

Answer by: drupalability
Posted: Feb 1, 2013
Vote up!
Vote down!

Thanks for the reply. I've actually made some progress here...

I've created a page where they can select their store. Users get forwarded to this page once they start to look at products. Initially, I was going to save this information in session, but I'm storing it in the cart now, which I think is the "correct" way to do it within DC.

I'm still not 100% sure on how to disable / remove the variations not associated with the selected store. I've found that I can use hook_node_view() to remove them if they don't match the store, but it just doesn't seem like it's the "correct" way. It seems like there should be a commerce hook to let me do it.

As for the "Why do they need to select a store?" question, it's because it's not *really* an e-commerce store that I'm building. It's more of an order placing system where the customers are going to end up picking up their order at their local store.

Answer by: jrb
Posted: Feb 1, 2013


This sounds very similar to a use case I am trying to implement. Could you post some more details of how you achieved this. I am relatively new to Drupal so need some help with hook_node_view. Thanks

- alenofarrell on December 6, 2013