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

Restrict Products to Membership(s) (4.0.x)

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 03-26-2007, 03:07 PM
 
gfiebich gfiebich is offline
 

Senior Member
  
Join Date: Feb 2003
Location: St. Paul, MN
Posts: 108
 

Default Restrict Products to Membership(s) (4.0.x)

This mod was done in x-cart gold 4.0.13. Once in place, the mod allows you to restrict item availability by Customer Membership(s). Stock X-Cart 4.0.x only allows Membership permissions to be set by Category (I believe 4.1.x now includes Membership at the Product level). Membership-restricted items behave in the same manner as a standard Disabled item (unavailable for viewing or ordering in the storefront). This mod adds 1 new field to the xcart_products table.

No warranty is expressed or implied. Make sure you backup your database and site files before attempting the mod.
  1. Paste the following into the "Apply SQL Patch" text field on the Patch/Upgrade page of your site admin:
    Code:
    alter table xcart_products add product_membership varchar(255) not null default '';
    Click apply.
  2. Open include/product_modify.php and look for
    PHP Code:
    # Update product data 
    In the db_query that appears below this, insert the following among similar lines.
    PHP Code:
    product_membership='$product_membership' 
  3. Open skin1/main/product_details.tpl and paste the following somewhere near the top (just below Availability works well).
    PHP Code:
    <TR
    {if 
    $productids ne ''}<TD width="15" class="TableSubHead"><INPUT type="checkbox" value="Y" name="fields[product_membership]"></TD>{/if}
      <
    TD class="FormButton" nowrap>{$lng.lbl_membership}:</TD>
      <
    TD class="ProductDetails"
        <
    INPUT type="text" name="product_membership" size="20" value="{ $product.product_membership }" class="InputWidth">
      </
    TD>
    </
    TR
  4. Open include/func.php and find
    PHP Code:
    if (!$always_select && ($product["forsale"] == "N" || ($product["forsale"] == "B" && empty($pconf)))) { 
    and replace with this
    PHP Code:
    #
        # Check for Product Membership
        #        
            
            
    if ($product["product_membership"] != "") {
            
                
    $productmembership explode(", "$product["product_membership"]);

                if (
    in_array("$membership"$productmembership)) {
                
                } else {
                    
    $offsale "true";
                }
                
            }
                
            
            if (!
    $always_select && ($offsale == "true" || $product["forsale"] == "N" || ($product["forsale"] == "B" && empty($pconf)))) { 
  5. Open include/search.php and find
    PHP Code:
    $search_condition .= " AND $sql_tbl[products].forsale='".$data["forsale"]."'"
    and replace with this
    PHP Code:
    $search_condition .= " AND $sql_tbl[products].forsale='".$data["forsale"]."' AND (($sql_tbl[products].product_membership='') OR ($sql_tbl[products].product_membership LIKE '%".$user_account["membership"]."%'))"

The mod is now installed. To restrict an item to a specific Membership (ie. Wholesale), type the Membership name in the new field on the product_modify screen (ex. Membership: Wholesale). This value is case-sensitive and must match the Membership name exactly. If you need multiple Membership levels to have access to the product, you can enter them all in this field, separated by commas (ex. Wholesale, Retail, Black Market). Leave the field empty to allow all customers to view the item.

Note that the mod searches the membership data with LIKE pattern matching. This means that if you have Membership levels with non-unique names, you may be inadvertently displaying restricted items to each of them (ex. "Membership: Retail" would also match "Membership: Full Retail").

To-do: Eventually, I want to use a Select box for Membership selection.

-Glen
__________________
NO LONGER USING X-CART - NOT ACTIVE IN THESE FORUMS
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not 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 04:02 AM.

   

 
X-Cart forums © 2001-2020