News:

Support the VirtueMart project and become a member

Main Menu

[Solved]Products visible by shopper group?

Started by Cleanshooter, October 28, 2011, 20:20:55 PM

Previous topic - Next topic

Cleanshooter

Is it possible to make certain products visible to certain groups of shoppers?  For example I have 3 products A, B and C  I want product A to be visible by both Shopper Group 1 and Shopper Group 2.  However I want B to only show up for Shopper group 1 and C should only show up for shopper group 2. 

I'm wondering if this would be possible "as is" in VirtueMart or if it would need to be developed as an extension?  Or maybe someone has already developed an extension that does this, bu then the question is does it work with VM2?

Thanks for any replies in advance.

Cleanshooter
- Cleanshooter

Cleanshooter

#1
I started working on a patch to do what I described above.  Problem is when it comes to .php, MVC and VM I'm still a beginner (We all start somewhere).  The link below is the patch file as it is now.

Shopper Group Product Visibility Patch

I've basically gotten the Shopper Group list to display where I want it and how I want it.  I've also manually created a relation table (similar to the 'product_categories' table).  I followed the way the Categories were added to the view because I want to be able to select multiple shoppergroups, however there is a ton of code associated with Categories (ordering, treeLists, rendering ect....) some of which I won't even pretend to understand.  I realized that I didn't need a lot of the category code but now I don't know how to get what I want to work.  The problem is that my experience with MVC and php is limited and I'm stuck on getting the data to the table.

It seems to me that the when I create $products->shoppers it doesn't create a shoppers array in the post data that way it does for categories.  So when I click save there is data in a $data['virtuemart_shopper_id'] and nothing in $data['shoppers'].  However I don't understand how to get that data into a shopper array or even if I need to.  I guessing I could use the data in the virtuemart_shopper_id array to feed into the table but I don't know how to do that.  I have also thought that I am missing something in the way that $data is packaged on POST.  And there is alos a thought nagging in my mind that I need to add something to model/shoppergroup.php in order to make this work. 

Right now when ever I click save (and the updateXrefAndChildTables function isn't commented out) it stores the data from an empty array into the table instead of any selection that I make.  When I manually add data to the table in myPhpAdmin it correctly displays in the view however if you click save it deletes all data for the product.

I really need this bit of functionality for my shop so I'm going to continue debugging and working till I get the patch working any help anyone can provide or pointing the the right direction will be greatly appreciated.

-Cleanshooter
- Cleanshooter

Cleanshooter

I finally got data into the table (the wrong way) but as long as it works IDC!!!!  I know just by looking at it, it's bass ackwards but at least now it works!

I'll update the patchTest.txt so the old link will have the working code.

-Cleanshooter
- Cleanshooter

Milbo

very interesting, thank you. Seems quite correct. I will add it to the core. (looks like cleaning and sorting code was useful :-) )
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Cleanshooter

#4
Ohh it's wasn't done yet yesterday... I just finished the patch this morning.  I have uploaded the new patch to the same link as above.

Patch Info:

  • Adds new table to install/install.sql
  • Adds update function so that new table contains default user view install/script.virtuemart.php
  • Updates models/product.php to support new functionality
  • Adds .php file to control new product_shoppers table to
  • Adds fields to: views/product/tmpl/product_edit_information.php

Since the patch is new it's needs some testing and it could very well break the cart for some users.  I hope it works well enough though.  Users will need to run the install/update tables function in the tools in order to populate the product_shoppers table. Also note the revision... I haven't tested this patch against the most recent SVN yet.

Also I should note that this only applies the 'viewing privileges' when the sortSearchListQuery funciton is called in models/product.php so it may not always work as expected. 

There is one thing that needs to be added to the TODO list for this patch.

If the user removes all the shopper groups assigned to a product no users will be able to see it - even the admin. So I'm guessing the best route is to add a function that prevents the removal of the default user.

As always thanks for all the hard work.  I hope this patch helps someone else too!

-Cleanshooter
- Cleanshooter

Milbo

$data['shoppers'] = $data['virtuemart_shoppergroup_id'];

I wrote you a pn, so that you get committ rights. Please just rename your shoppers to shoppergroups.

More important is that it works without any shoppergroups set. When you have committed your code, I can easier work with you on it. In General we have the coding rule which means, when nothing is set, take the standard. Important, NEVER set the standard in the individual row.

What means that? When a shopper should be in the standard shoppergroup => no shoppergroup is set. We use this rule everywhere. The advantage is that you can easily change the default value without editing everything which uses this standard.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Cleanshooter

Got your e-mail thanks for the invite.  I downloaded skype this morning and signed on (for the first time in a long time).  After reading your comments it clicked in my head how to fix the bug with the products not showing up unless the default was set.  I've already got the bug fixed and updated on my end I'll wait for commit privileges to submit the changes.

I also understand the need for this to work the way you explained and it makes sense (not presetting a default and all...).  I have already replaced the variable names across all the changes I've made so that they conform to the standard.  Again I'll submit changes once I get commit privs :)

Can't wait to contribute more to the project!

-Cleanshooter
- Cleanshooter

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/