Forums / Setting Up Categories, Products, Attributes / Products that can only be purchased once.

Products that can only be purchased once.

Locked

Views: 2,006

Results 1 to 17 of 17
This thread is locked. New replies are disabled.
27 May 2010, 4:31 PM
#1
youngblood avatar

youngblood

New Zenner

Join Date:
Apr 2010
Posts:
59
Plugin Contributions:
0

Products that can only be purchased once.

Hello Zen Community,

I've had some recent success with finding answers on the boards, so I figured I'd throw another nail biter out here to see what the masses think.

I've been having some issues finding an appropriate thread for this, so if its already been discussed, please link me there.

I need an addon/module that will allow for the creation of products to be bought only once by customer. The products are Feebie promotional items. I'd like the ability to sort the customers by IP and account so I don't have multiple people in the same house mooching Freebies.

The sorting feature is just icing, but I'm desperate for the 'buy once per customer feature'.

Any words of wisdom?

Thanks in advance for the time and advice.

Jonah

27 May 2010, 5:37 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Products that can only be purchased once.

Is there anything that identifies these problems such as they all are in the same categories_id where that categories_id is set as these Products master_categories_id in the products table?

You could write a look for the products_id or based on master_categories_id something and then use it in the function for the display on the add to cart/buy now buttons so that it will change it from a normal Add to Cart to something else like:
You got yours!

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

27 May 2010, 6:21 PM
#3
youngblood avatar

youngblood

New Zenner

Join Date:
Apr 2010
Posts:
59
Plugin Contributions:
0

Re: Products that can only be purchased once.

Yes actually,

The products in question have the same category ID, and at this point, theres no reason to think that would ever change. All of our special offers would be derived from the same cat. selection that remains unposted.

Our plan is to send out a link...and a coupon code to initalize the free offers. For Example:

One of our offers is meant to be free of cost the customer. So, the product itself is written in at 0.00$ and then the coupon code would activate free shipping. I'm aware that there are many other ways to get free shipping and products than to write it in as 0.00, but this is the best way for us currently with our other formatting and addons installed.

Ajeh, can you write this php function you speak of? The master cat id is 17. I'd put a link up for you, but I don't want everyone to see them. Just putting that number up should keep it viewable to the wise and wonderful only.

27 May 2010, 8:19 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Products that can only be purchased once.

Yes I could ... but then I'd have to kill you ... :eek:

This took me a bit to work out what I think is the best solution ...

1 if not logged in and this is one of the Free Products, the customer is told to login ...

2 if logged in the orders are checked to see if the customer has already obtained the product ...

You can customize the function file:
/includes/functions/functions_general.php

and around line 1144 change it to read:

    default:
      $return_button = $link;
      break;
    }

// bof: do not allow customer to add to cart if already purchased
// if not logged in and a free product make login
if (!$_SESSION['customer_id'] && zen_get_products_category_id($product_id) == 60) {
  return 'login for free product';
}

if (zen_get_products_category_id($product_id) == 60) {
      $chk_product_purchased_query = "select distinct op.products_id, o.orders_id
                              from " . TABLE_ORDERS_PRODUCTS . " op
                              left join " . TABLE_ORDERS . " o on o.orders_id = op.orders_id
                              where op.products_id = '". (int)$product_id . "'
                              and o.customers_id='" . $_SESSION['customer_id'] . "'";

     $chk_product_purchased = $db->Execute($chk_product_purchased_query);

    if (!$chk_product_purchased->EOF) {
      return 'too bad so sad';
    }
}

// eof: do not allow customer to add to cart if already purchased

    if ($return_button != $link and $additional_link != false) {
      return $additional_link . '<br />' . $return_button;
    } else {
      return $return_button;
    }
  }

This way you can prevent having to test in the cart later, after they login, if they already got it and remove it from the cart or make the customer remove it before checking out ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

27 May 2010, 8:20 PM
#5
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Products that can only be purchased once.

NOTE: this assumes the master_categories_id on these Products is 60 ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

27 May 2010, 9:38 PM
#6
youngblood avatar

youngblood

New Zenner

Join Date:
Apr 2010
Posts:
59
Plugin Contributions:
0

Re: Products that can only be purchased once.

Too Bad, Sooo Sad....

Ajeh wins again.

Vote Ajeh for world dictator!

Ajeh, this is phenomial work...Thank you.

I must ask for a glass of milk, and request that I also get the code to make it related to individual items (not its catagorey ID). Do you like e-cigarettes? :-p

Jonah Youngblood
http://www.primevapor.com

27 May 2010, 10:28 PM
#7
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Products that can only be purchased once.

Thanks for the offer but it is bad enough I smoke the dang things than try something else that has yet to be proven won't kill me ... I know these will eventually ... but then again ... I drank milk as a child so that will get me too ... :cool:

Meanwhile ...

You could adapt the code from:

if (zen_get_products_category_id($product_id) == 60) {

to something like:

if ( in_array((int)$product_id, array(6, 200, 34)) ) {

where 6, 200 and 34 are the products_id you do not want ...

Or for both to cover that whole Category plus other individual products_id numbers:

if (zen_get_products_category_id($product_id) == 60 || in_array((int)$product_id, array(6, 200, 34))) {

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

27 May 2010, 10:50 PM
#8
youngblood avatar

youngblood

New Zenner

Join Date:
Apr 2010
Posts:
59
Plugin Contributions:
0

Re: Products that can only be purchased once.

I've noticed that Zen product ID's are usually called on with the master category ID followed by an individual product ID for that category.

Just to make sure...Zen Cart does not overlap these individual product IDs? Meaning, that never at anytime any two products from any two category's would have the same ID?

Oh, and I know solicitation on here is bad, so please don't think I'm trying to sell anything, but you said they weren't proven to be safe. I beg to differ.....several health studies have already been released, here's a prominent one from New Zealand that's fairly recent.

If we had a toxic product, the FDA would shut us down very quickly.

health report link: http://www.healthnz.co.nz/RuyanCartridgeReport30-Oct-08.pdf

I often find that its the lack of information to be the most damaging aspect of the business my comrades and I are in.

Thank you again for your help Ajeh, If I can ever offer you anything with reason as return...please do not hesitate to find me!

With Profound Gratitude,

Jonah

27 May 2010, 10:54 PM
#9
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Products that can only be purchased once.

Not a problem ...

The products_id of a Product is unique ... if you link a product to multiple categories there is still 1 product but that is referenced in the products_to_categories table to say which categories the Product is in ...

The master_categories_id is used to identify which Category a Product is "owned" by as in if there is a pricing issue or a navigation issue the master_categories_id indicates which Category to follow ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

27 May 2010, 10:57 PM
#10
youngblood avatar

youngblood

New Zenner

Join Date:
Apr 2010
Posts:
59
Plugin Contributions:
0

Re: Products that can only be purchased once.

Good to know,

Where is my error? I think its in the Session ID line for the customer...I'm a bit of a newbie at php.

// bof: do not allow customer to add to cart if already purchased
// if not logged in and a free product make login

if (!$_SESSION['customer_id'] && ( in_array((int)$product_id, array(65, 64, )) ) {
return 'login for free product';
}

if ( in_array((int)$product_id, array(65, 64, )) ) {
  $chk_product_purchased_query = "select distinct op.products_id, o.orders_id
                          from " . TABLE_ORDERS_PRODUCTS . " op
                          left join " . TABLE_ORDERS . " o on o.orders_id = op.orders_id
                          where op.products_id = '". (int)$product_id . "'
                          and o.customers_id='" . $_SESSION['customer_id'] . "'";

 $chk_product_purchased = $db->Execute($chk_product_purchased_query);

if (!$chk_product_purchased->EOF) {
  return 'You have already received this offer!';
}

}

// eof: do not allow customer to add to cart if already purchased

28 May 2010, 8:10 AM
#11
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Products that can only be purchased once.

Try this ... paren issues and that , after the products_id in the array ...

// bof: do not allow customer to add to cart if already purchased
// if not logged in and a free product make login


if (!$_SESSION['customer_id'] && in_array((int)$product_id, array(65, 64 )) ) {
  return 'login for free product';
}


if ( in_array((int)$product_id, array(65, 64 )) ) {
  $chk_product_purchased_query = "select distinct op.products_id, o.orders_id
    from " . TABLE_ORDERS_PRODUCTS . " op
    left join " . TABLE_ORDERS . " o on o.orders_id = op.orders_id
    where op.products_id = '". (int)$product_id . "'
    and o.customers_id='" . $_SESSION['customer_id'] . "'";

  $chk_product_purchased = $db->Execute($chk_product_purchased_query);

  if (!$chk_product_purchased->EOF) {
    return 'You have already received this offer!';
  }
}

// eof: do not allow customer to add to cart if already purchased
  

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

1 Jun 2010, 1:33 PM
#12
youngblood avatar

youngblood

New Zenner

Join Date:
Apr 2010
Posts:
59
Plugin Contributions:
0

Re: Products that can only be purchased once.

Thank you once again Ajeh,

I aspire to achieve your level of understanding of php and generosity.

Till next time!

1 Jun 2010, 2:37 PM
#13
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Products that can only be purchased once.

You are most welcome ... thanks for the update that this is working for you now to only allow the purchase of some products once ... :smile:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

1 Jun 2010, 6:42 PM
#14
youngblood avatar

youngblood

New Zenner

Join Date:
Apr 2010
Posts:
59
Plugin Contributions:
0

Re: Products that can only be purchased once.

Well this is certainly frustrating....

With either of the codes you've provided, when installed....I can confirm that it does indeed make the selected products a "buy once" feature.

However, it also causes a blank page to display whenever a user creates a new account or tries to log into an existing one.

Launches Distress Flare

Any and all assistance is appreciated, this is outside of my knowledge.

1 Jun 2010, 10:57 PM
#15
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Products that can only be purchased once.

If in v1.3.9 ... check your /cache for error logs ...

If not in v1.3.9 ... get the Debug Tool from the Free Software Add Ons and see what error message you are getting ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

2 Jun 2010, 2:30 PM
#16
youngblood avatar

youngblood

New Zenner

Join Date:
Apr 2010
Posts:
59
Plugin Contributions:
0

Re: Products that can only be purchased once.

Problem Solved -

Initially, I had used your category code twice with different ID's. I did not use an array as suggested.

The second time I had put the code in the wrong line and therefore caused some syntax errors with php.

Finally, Using the product ID code with what you wrote worked. I guess I was a bit fatigued yesterday.

So, for anyone else looking to do the same, listen to Ajeh! and don't try to do your own thing like I did. It will only humble you.

Thanks Ajeh for your continued patience with me....

Jonah

2 Jun 2010, 2:40 PM
#17
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Products that can only be purchased once.

Glad to hear that this is now working for you ... :unsure:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!