Module prevents ability to add more than 1 of any product variant to cart

Created on 18 January 2020, almost 5 years ago
Updated 20 September 2024, 2 months ago

When commerce_license is installed multiples of any product type's variants which don't have licenses cannot be added to the shopping cart. I have a normal (non license) product type of 'T-Shirt' which produces this alert when trying to add a second item to the cart:

It makes sense that only 1 license can be purchased per user but this rule shouldn't be restricting or interfering with multiples of tangible (non license providing) products from being ordered in the same store.

Searching 'you may only have' produced this:

The_Glitches MacBook-Pro:My Suite user$ grep -Ri 'you may only have' *
modules/contrib/commerce_license/src/LicenseOrderProcessorMultiples.php:  drupal_set_message(t("You may only have one of product-label in your cart.", [
modules/contrib/commerce_license/src/EventSubscriber/LicenseMultiplesCartEventSubscriber.php:    drupal_set_message(t('You may only have one of @product-label in <a href="@cart-url">your cart</a>.', [
modules/contrib/commerce_license/src/EventSubscriber/LicenseMultiplesCartEventSubscriber.php:    drupal_set_message(t('You may only have one of @product-label in your cart.', [

I hope this helps.

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia the_glitch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¨πŸ‡­Switzerland tcrawford

    We encountered the same issue. Maybe we mis-configured the assignment of order item types. However, I think unless there is a important reason there is quite a bit of overhead to create different order items for licenses. Would there be any reason not to extend the guard / add a second guard to check if the purchased entity has a license type field? We are using this on a customer project with no adverse impacts to date.

    ```
    // Skip purchasable entities that are not licenses.
    if (!$order_item->getPurchasedEntity()->hasField('license_type') ||
    $order_item->getPurchasedEntity()->get('license_type')->isEmpty()) {
    return;
    }

  • πŸ‡¬πŸ‡§United Kingdom joachim

    > However, I think unless there is a important reason there is quite a bit of overhead to create different order items for licenses

    You only need one order item type to work with licenses, so I don't see how that's a lot of overhead.

    Commerce core allows different order item types precisely for this sort of functionality -- we get to define a field on the order item, which we need to licenses to work properly.

  • πŸ‡ΊπŸ‡ΈUnited States herkimer

    @tcrawford // #16

    Thank you for posting this -- it works great on our site.

    We enabled and configured the License module, sold about 150 license-enabled products, and THEN realized that we had botched the installation (did not create a specific Order Type for licenses). Our specific problem was similar to the above reports: that non-license products could not be added-to-cart in quantities > 1.

    After re-tracing all of the README steps, it became clear that the only way to fix our mistake was a clean install -- and that would have really goofed-up the 150 already-existing customer orders.

    Unless there are compelling reasons for not doing so -- it would be nice to see tcrawford's code added to the module. Thanks.

Production build 0.71.5 2024