Problem/Motivation

Currently it is impossible/difficult to make the approval checkbox required on the cart page and the text displayed are the same for all product categories.

Proposed resolution

Add a configuration in the view field setting to make this field required on the cart page.

Also included in the patch, the text displayed respective to their term selected. And since not all terms has a specific approval text, I've also added a configuration to add a default approval text.

Comments

kkumaren created an issue. See original summary.

kkumaren’s picture

kkumaren’s picture

Forgot to save the default approval text

kkumaren’s picture

Status: Active » Needs review
kkumaren’s picture

Here is an updated patch with latest commits

kkumaren’s picture

Status: Needs review » Reviewed & tested by the community
kkumaren’s picture

Status: Reviewed & tested by the community » Needs review
alexpott’s picture

+++ b/src/Plugin/views/field/Approve.php
@@ -100,22 +153,24 @@ class Approve extends FieldPluginBase {
+          if ($productReferencedEntity->getEntityTypeId() == 'taxonomy_term' &&
+            $productReferencedEntity->hasField('field_require_approval')) {
             return [
-              'lock' => TRUE,
-              'text' => $referencedEntity->get('field_require_approval_text')->getValue()[0]['value'],
+              'text' => $productReferencedEntity->get('field_require_approval_text')->getValue()[0]['value'],
             ];
           }

I think you need to do test for emptiness too... something like !$productReferencedEntity->get('field_require_approval_text')->isEmpty()

Otherwise this code can produce warnings.

kkumaren’s picture

Added test to check if field is empty.
Also test if checkbox require approval is checked

travis-bradbury’s picture

Status: Needs review » Needs work

I think you have the same problem for field_require_approval now.

+          if ($productReferencedEntity->getEntityTypeId() == 'taxonomy_term' &&
+            $productReferencedEntity->hasField('field_require_approval')) {
+            if ($productReferencedEntity->get('field_require_approval')->getValue()[0]['value'] == TRUE) {
+              if (!$productReferencedEntity->get('field_require_approval_text')->isEmpty()) {

The requiresApproval method's contract states that it returns an array or false

    * @return bool|array
    *   Array with values if it requires manual approval, FALSE otherwise.
    */

but it's actually returning an array, true, or null.

+            if ($productReferencedEntity->get('field_require_approval')->getValue()[0]['value'] == TRUE) {
+              if (!$productReferencedEntity->get('field_require_approval_text')->isEmpty()) {
+                return [
+                  'text' => $productReferencedEntity->get('field_require_approval_text')->getValue()[0]['value'],
+                ];
+              }
+              return TRUE;
+            }
           }
         }
       }

so that's either a bug or the spec needs to be updated.

alexpott’s picture

+++ b/src/Form/CommerceApproveManagementForm.php
@@ -89,6 +89,13 @@ class CommerceApproveManagementForm extends ConfigFormBase {
+      '#default_value' => $config->get('default_approval_text') ?? t('I have verified this product is correct.'),

The default should be supplied in configuration and this needs to be in the config schema too.

skyredwang’s picture

Status: Needs work » Needs review
StatusFileSize
new7.42 KB

I removed the "default approval text" config, as it seems we haven't really used it. Therefore, we don't need a config for that either.

  • skyredwang committed 96e3c77 on 8.x-1.x
    Issue #3055790 by kkumaren, skyredwang, alexpott, tbradbury: Make...
skyredwang’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.