Commit 4ebc6bc0 authored by Jigish Chauhan's avatar Jigish Chauhan
Browse files

Issue #3274586: Threshold set

parent 121ae0a0
Loading
Loading
Loading
Loading

commerce_user_points.info.yml

100755 → 100644
+5 −0
Original line number Diff line number Diff line
@@ -7,3 +7,8 @@ dependencies:
configure: commerce_user_points.admin_settings

core_version_requirement: ^8.8.0 || ^9.0

# Information added by Drupal.org packaging script on 2020-06-30
version: '9.0.x'
project: 'commerceuserpoints'
datestamp: 1593528474
+9 −0
Original line number Diff line number Diff line
commerce_user_points.admin_settings:
  title: 'User Points Configuration'
  route_name: commerce_user_points.admin_settings
  base_route: commerce_user_points.admin_settings

commerce_user_points.admin_threshold_amount_settings:
  title: 'Threshold Amount Configuration'
  route_name: commerce_user_points.admin_threshold_amount_settings
  base_route: commerce_user_points.admin_settings
+3 −2
Original line number Diff line number Diff line
@@ -8,9 +8,10 @@ use Drupal\Core\Entity\EntityTypeManager;
use Drupal\node\Entity\Node;

/**
 * Class OrderCompleteSubscriber.
 * Provides methods for ordercomplete..
 *
 * @package Drupal\commerce_user_points
 * Class OrderCompleteSubscriber.
 */
class OrderCompleteSubscriber implements EventSubscriberInterface {

@@ -63,7 +64,7 @@ class OrderCompleteSubscriber implements EventSubscriberInterface {
    $currentAdjustments = $order->getAdjustments();
    if (!empty($currentAdjustments)) {
      foreach ($currentAdjustments as $adjustmentValue) {
        // @todo - update
        // @todo update
        if ($adjustmentValue->getLabel() == 'User Points Deduction') {
          $pointsAmount = $adjustmentValue->getAmount();
          $userPoints = abs($pointsAmount->getNumber());
+4 −1
Original line number Diff line number Diff line
@@ -132,6 +132,9 @@ class ThresholdAmountConfigurationForm extends ConfigFormBase {
        ->set('user_threshold_amount_' . $value->id(), $values['user_threshold_amount_' . $value->id()])
        ->save();
    }
  }

    $this->config('commerce_user_threshold_amount.settings')
      ->set('user_threshold_amount', $values['user_threshold_amount'])
      ->save();
  }
}
+56 −23
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\commerce_user_points\Plugin\Commerce\CheckoutPane;

use Drupal\user\Entity\Role;
use Drupal\commerce_store\Entity\Store;
use Drupal\commerce_product\Entity\Product;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase;
@@ -108,6 +109,11 @@ class CommerceUserPoints extends CheckoutPaneBase implements CheckoutPaneInterfa
   *   Description of the return value, which is a array.
   */
  public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
    $form_threshold = \Drupal::formBuilder()->getForm('Drupal\commerce_user_points\Form\ThresholdAmountConfigurationForm');

    $current_user = \Drupal::currentUser();
    $roles = $current_user->getRoles();
    $role = Role::loadMultiple();

    $arrNidPoints = $totalUsablePoints = [];

@@ -126,22 +132,32 @@ class CommerceUserPoints extends CheckoutPaneBase implements CheckoutPaneInterfa
    if (!$flagPointsApplied && !empty($user->id())) {
      // The options to display in our form radio buttons.
      $options = [
        '0' => t("Don't use points"),
       // '0' => t("Don't use points"),
        '1' => t('Use all usable points'),
        '2' => t('Use Specific points'),
      ];

      // Get all valid user points.
      $arrNidPoints = $this->calculateUsablePoints();

      $totalUsablePoints = round($arrNidPoints['total_usable_points']);

      $price = $complete_form['sidebar']['order_summary']['#order_entity'];
      $total_value = $price->get("total_price")->getValue();

      if (round($total_value[0]['number']) > round($form_threshold['user_threshold_amount']['#default_value'])) {
        $pane_form['user_points_redemption_type'] = [
          '#type' => 'radios',
        '#title' => t('User points Redeem'),
          '#title' => t('User points Redeems'),
          '#options' => $options,
          '#description' => t('You have points at the moment') . " " . $totalUsablePoints,
          '#default_value' => '0',
          '#states' => [
            'visible' => [
              ':input[name="coupons[user_points]"]' => [
                'checked' => TRUE,
              ],
            ],
          ],
        ];

        $pane_form['user_points_redemption'] = [
@@ -156,7 +172,16 @@ class CommerceUserPoints extends CheckoutPaneBase implements CheckoutPaneInterfa
            ':input[name="coupons[user_points_redemption_type]"]' => ['value' => '2'],
          ],
        ];
        $pane_form['user_points'] = [
          '#type' => 'checkbox',
          '#title' => t('User points Redeems'),
          '#default_value' => '0',
          '#attributes' => ['class' => ['user-point-checkbox']],
        ];
      }

    }
    $pane_form['#attached']['library'][] = 'commerce_user_points/referral_link_library';
    return $pane_form;
  }

@@ -193,7 +218,11 @@ class CommerceUserPoints extends CheckoutPaneBase implements CheckoutPaneInterfa
          $totalUsablePoints = round($arrNidPoints['total_usable_points']);

          if ($totalUsablePoints < $thresholdValue) {
            $form_state->setError($pane_form, $this->t('Curently you have @totalUsablePoints point(s) in your account. You can utilize points after you reached to @thresholdValue points.', ['@totalUsablePoints' => $totalUsablePoints, '@thresholdValue' => $thresholdValue]));
            $form_state->setError($pane_form, $this->t('Curently you have @totalUsablePoints point(s) in your account. You can utilize points after you reached to @thresholdValue points.',
              [
                '@totalUsablePoints' => $totalUsablePoints,
                '@thresholdValue' => $thresholdValue,
              ]));
          }

          if ($this->order->hasItems()) {
@@ -214,7 +243,11 @@ class CommerceUserPoints extends CheckoutPaneBase implements CheckoutPaneInterfa
          $totalUsablePoints = round($arrNidPoints['total_usable_points']);

          if ($totalUsablePoints < $thresholdValue) {
            $form_state->setError($pane_form, $this->t('Curently you have @totalUsablePoints point(s) in your account. You can utilize points after you reached to @thresholdValue points.', ['@totalUsablePoints' => $totalUsablePoints, '@thresholdValue' => $thresholdValue]));
            $form_state->setError($pane_form, $this->t('Curently you have @totalUsablePoints point(s) in your account. You can utilize points after you reached to @thresholdValue points.',
              [
                '@totalUsablePoints' => $totalUsablePoints,
                '@thresholdValue' => $thresholdValue,
              ]));
          }

          break;
+1 −1

File changed.

Contains only whitespace changes.

Loading