Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Membership by "code" and hide non-membership items

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 03-24-2017, 09:09 AM
 
garyhoffmann garyhoffmann is offline
 

Advanced Member
  
Join Date: Sep 2009
Posts: 37
 

Default Membership by "code" and hide non-membership items

I have two different things regarding memberships that I'm interested in doing. I wonder if anyone else has done these or knows how to do these.

First, my customer is currently in trial with 5.3.2.3 but will update to the latest in the 5 branch when they go live.

They would like us to put a registration code on the register page that allows someone to enter a code. Based on the code the user enters, they would then like the user to be placed into a particular membership immediately/automatically.

They have also requested that when a registered member that is part of a membership logs in, they only see products/categories associated with their membership and not the "public"/non-membership items.

We discussed the possibility of having all items be part of a membership but that will not work because they still need items that are public for users that are not part of a membership.

Any thoughts on this would be very welcomed. Again, this is a V5 customer.

Thank you in advance for any ideas on this.
Gary.
__________________
Gary
Reply With Quote
  #2  
Old 03-31-2017, 03:25 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Membership by "code" and hide non-membership items

> They would like us to put a registration code on the register page that allows someone to enter
> a code. Based on the code the user enters, they would then like the user to be placed into
> a particular membership immediately/automatically.

Although this is not a complex modification, it requires more changes than can be explained here, in the forums. In a few words you should add a new field widget to the registration form, and then check its value in the controller class that adds the user.

> They have also requested that when a registered member that is part of a membership logs in, they
> only see products/categories associated with their membership
> and not the "public"/non-membership items.

The method that filter products depending on the membership condition is this one:
\XLite\Model\Repo\Product::addMembershipCondition( )

I think you should look into decorating this method from your custom module and removing the "OR membership.membership_id IS NULL" part of the condition.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #3  
Old 03-31-2017, 03:58 AM
 
garyhoffmann garyhoffmann is offline
 

Advanced Member
  
Join Date: Sep 2009
Posts: 37
 

Default Re: Membership by "code" and hide non-membership items

Thanks Alex - I really need to learn how to extend XC5. I think it's time to spend some time on a test installation to do some learning.

What is the best way to learn this? I'm looking for that "lightbulb moment" - the moment the light bulb turns on in your mind and you say "ah ha".

Thanks,
Gary.
__________________
Gary
Reply With Quote
  #4  
Old 03-31-2017, 05:41 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Membership by "code" and hide non-membership items

Did you check this site?
http://devs.x-cart.com/
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote

The following user thanks qualiteam for this useful post:
ITVV (03-31-2017)
  #5  
Old 04-27-2017, 03:12 PM
 
garyhoffmann garyhoffmann is offline
 

Advanced Member
  
Join Date: Sep 2009
Posts: 37
 

Default Re: Membership by "code" and hide non-membership items

How do I go about requesting a quote again?
__________________
Gary
Reply With Quote
  #6  
Old 04-29-2017, 06:32 AM
 
garyhoffmann garyhoffmann is offline
 

Advanced Member
  
Join Date: Sep 2009
Posts: 37
 

Default Re: Membership by "code" and hide non-membership items

I created a module - I put in the code to limit the products by membership to only those products associated with the membership.

After doing so, I noticed the products were fine, but not the categories. So, I put similar code in a module which extends the category. However, the problem I am having is that it doesn't work. I'm still getting all the categories.

I put logging in so I can see that my code is running, but it's not limiting the categories as I would have expected.

It should only be returning categories for which the membership id is 2 in this case, but I am getting them all back.

The PHP code is pretty straight forward:

Code:
namespace XLite\Module\TechAnalysts\ProductsForMemberships\Model\Repo; /** * The "category" repo class */ abstract class Category extends \XLite\Model\Repo\Category implements \XLite\Base\IDecorator { protected function addMembershipCondition(\Doctrine\ORM\QueryBuilder $queryBuilder, $alias = null) { if ($this->getMembershipCondition()) { $alias = $alias ?: $this->getDefaultAlias(); $limit = \XLite\Core\Config::getInstance()->TechAnalysts->ProductsForMemberships->limit_to_membership; $membership = \XLite\Core\Auth::getInstance()->getMembershipId(); if ($membership) { $whereClause = 'membership.membership_id = :membershipId'; if ($limit != 'Y') { $whereClause .= ' OR membership.membership_id IS NULL'; } \XLite\Logger::logCustom('techanalysts',$whereClause . ': ' . $membership,true); $queryBuilder->leftJoin($alias . '.memberships', 'membership') ->andWhere($whereClause) ->setParameter('membershipId', \XLite\Core\Auth::getInstance()->getMembershipId()); } else { $queryBuilder->leftJoin($alias . '.memberships', 'membership') ->andWhere('membership.membership_id IS NULL'); } } } }

I'm not sure what's causing my problems at this point nor where to go to find more information.

I did notice that the Category is using $queryBuilder->leftJoin whereas the Product is using $queryBuilder->linkLeft. I'm not sure if that's part of the problem or not.
__________________
Gary
Reply With Quote
  #7  
Old 05-03-2017, 06:50 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Membership by "code" and hide non-membership items

The code looks good except users having no membership will see all categories due to the "if ($membership)" condition.
Is it the problem that you face?
Or does it happen to users having a membership?

You may use \XLite\Logger::logCustom('debug', [ /* array of your variables there */ ] ); to log parameters to a log file to check what exactly happens inside your method (and whether it is called at all).
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #8  
Old 05-03-2017, 06:57 AM
 
garyhoffmann garyhoffmann is offline
 

Advanced Member
  
Join Date: Sep 2009
Posts: 37
 

Default Re: Membership by "code" and hide non-membership items

The problem I am facing is that when a user logs in WITH membership, they are seeing all the categories rather than just the ones assigned to that membership.

Thank you for following up.
__________________
Gary
Reply With Quote
  #9  
Old 05-03-2017, 10:23 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Membership by "code" and hide non-membership items

I believe you don't need the ",true" when calling the logCustom() method.
I.e. it should be something like this:
PHP Code:
\XLite\Logger::logCustom('techanalysts',['where' => $whereClause'membership' => $membership]); 

Does it create the "techanalysts.log.*****" file in the var/log/ directory?
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions

Last edited by qualiteam : 05-03-2017 at 10:25 AM.
Reply With Quote
  #10  
Old 05-03-2017, 10:39 AM
 
garyhoffmann garyhoffmann is offline
 

Advanced Member
  
Join Date: Sep 2009
Posts: 37
 

Default Re: Membership by "code" and hide non-membership items

Yes, it creates the file - the "true" tells it to log more information according to the docs in devs.x-cart.com.

From this page:
http://devs.x-cart.com/en/misc/debugging_x-cart.html

Logging

If you need to dump some variable during script execution and you cannot call die(), then you can log the variable during execution by using the following method:
\XLite\Logger::logCustom($log_name, $string_to_log, $whether_to_add_backtrace);


I think we are getting off topic a bit - I'm not having a problem with logging - I'm having a problem with the HOME PAGE still displaying categories that are not assigned to my membership. it is displaying all categories rather than just the ones for my membership. This is NOT a problem on interior pages, only the home page.
__________________
Gary
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 06:08 PM.

   

 
X-Cart forums © 2001-2020