X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Restrict Products to Membership(s) (4.0.x) (https://forum.x-cart.com/showthread.php?t=30003)

gfiebich 03-26-2007 03:07 PM

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:

    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:


  3. Open skin1/main/product_details.tpl and paste the following somewhere near the top (just below Availability works well).
    PHP Code:

    $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">

  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.


All times are GMT -8. The time now is 07:48 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.