Add restriction a coupon usage for limited per-customer

Created on 24 December 2021, almost 3 years ago
Updated 10 November 2023, about 1 year ago

Problem/Motivation

The 8.x-2.19 version of Commerce has added functionality with the ability to limit the use of promotion per customer.
This added feature doesn't work properly with this module.

Proposed resolution

For this need to add checking availability to this added field.

πŸ› Bug report
Status

Fixed

Version

1.1

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine dd_leo Lutsk

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.

  • πŸ‡­πŸ‡·Croatia valic Osijek
  • Issue was unassigned.
  • Status changed to Active almost 2 years ago
  • πŸ‡­πŸ‡·Croatia valic Osijek

    Think we can almost completely remove duplicate code, and rely on parent method check, if it returns true we do check for conditions than

  • πŸ‡ͺπŸ‡ΈSpain interdruper

    Besides (correctly) handle the coupon usage per-customer limit functionality, the latest commit also relies in the parent coupon entity date fields:

        $fields['start_date'] = BaseFieldDefinition::create('datetime')
          ->setLabel(t('Start date'))
          ->setDescription(t('The date the coupon becomes valid.'))
          ->setRequired(FALSE)
          ->setSetting('datetime_type', 'datetime')
          ->setSetting('datetime_optional_label', t('Provide a start date'))
          ->setDefaultValueCallback('Drupal\commerce_promotion\Entity\Promotion::getDefaultStartDate')
          ->setDisplayOptions('form', [
            'type' => 'commerce_store_datetime',
            'weight' => 5,
          ]);
    
        $fields['end_date'] = BaseFieldDefinition::create('datetime')
          ->setLabel(t('End date'))
          ->setDescription(t('The date after which the coupon is invalid.'))
          ->setRequired(FALSE)
          ->setSetting('datetime_type', 'datetime')
          ->setSetting('datetime_optional_label', t('Provide an end date'))
          ->setDisplayOptions('form', [
            'type' => 'commerce_store_datetime',
            'weight' => 6,
          ]);
    

    ... but the parent definitions are not backward-compatible with the previous definitions used by this module:

        $fields['start_date'] = BaseFieldDefinition::create('datetime')
          ->setLabel(t('Start date'))
          ->setDescription(t('The date the promotion becomes valid.'))
          ->setRequired(FALSE)
          ->setSetting('datetime_type', 'date')
          ->setDisplayOptions('form', [
            'type' => 'datetime_default',
            'weight' => 8,
          ]);
    
        $fields['end_date'] = BaseFieldDefinition::create('datetime')
          ->setLabel(t('End date'))
          ->setDescription(t('The date after which the promotion is invalid.'))
          ->setRequired(FALSE)
          ->setSetting('datetime_type', 'date')
          ->setDisplayOptions('form', [
            'type' => 'commerce_end_date',
            'weight' => 9,
          ]);
    

    So any dates defined on coupons created previously using this module are not available after applying the last commit...

  • Status changed to RTBC over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia elc

    In combination with πŸ› Remove local start_date and end_date base fields and fix existing dates Fixed , this fixes the introduced incompatibilities of the now parent entity handled coupon properties of "per user", and "start_date/end_date".

  • Status changed to Fixed about 1 year ago
  • πŸ‡­πŸ‡·Croatia valic Osijek
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024