Jump to content

Limit the amount of products a user can purchase


Spinbox
 Share

Recommended Posts

I want to limit the purchase of some 'event'-typed product to 1 per user.

Currently when an event is purchased the user get's added to a pagearrayfield which in turn grants them access to some pages.

How could I limit the amount of a product to be added to the cart to 1? And after they bought it, how can I prevent them from buying it again?

  • Like 1
Link to comment
Share on other sites

22 hours ago, Spinbox said:

I want to limit the purchase of some 'event'-typed product to 1 per user.

Currently when an event is purchased the user get's added to a pagearrayfield which in turn grants them access to some pages.

How could I limit the amount of a product to be added to the cart to 1? And after they bought it, how can I prevent them from buying it again?

Hi @Spinbox,

Just acknowledging that I have seen this. I'll get back to you with a detailed answer. There's various ways to approach this (all easy ?).

Link to comment
Share on other sites

  • 3 weeks later...

For the present question about 1 product per user, here is example code:

<?php

namespace ProcessWire;

$eventProductID = 2678;

$customerEmail = 'wario_best@gmail.com';
/*
NOTES
1. line-time -> padloper-order-line-item (order line item template)
2. product_id -> subfield in padloper_order_line_item field with product ID value
3. parent.order_customer -> Order is the parent of line items. padloper_order_customer is the field with customer details
*/

// $boughtTicket = $padloper->get("template=line-item, line_item.product_id={$eventProductID},parent.order_customer.email={$customerEmail}");
// if ($boughtTicket instanceof NullPage) {
// 	// NOT YET BOUGHT TICKET 
// } else {
// 	// BOUGHT TICKET ALREADY

// }

# OR

$boughtTicketID = (int) $padloper->getRaw("template=line-item, line_item.product_id={$eventProductID},parent.order_customer.email={$customerEmail}", 'id');


if (empty($boughtTicketID)) {
	// NOT YET BOUGHT TICKET 

} else {
	// BOUGHT TICKET ALREADY

}

Let me know if you need clarification.

Sorry for the delay!

Thanks.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...