Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions assets/src/frontend/components/CustomerSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export default {
},

'orderdata.customer_id'(newVal) {
this.serachInput = newVal ? this.orderdata.billing.first_name + ' ' + this.orderdata.billing.last_name : '';
this.serachInput = newVal ? this.getCustomerDisplayName(this.orderdata.billing.first_name, this.orderdata.billing.last_name, this.orderdata.billing.email) : '';
}

},
Comment on lines 228 to 232

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Potential TypeError when orderdata.billing is missing

this.orderdata.billing is dereferenced without a null-check.
When the order arrives from an endpoint where the billing object is not yet populated, the watcher will throw (Cannot read property 'first_name' of undefined) and break reactivity.

- this.serachInput = newVal ? this.getCustomerDisplayName(this.orderdata.billing.first_name, this.orderdata.billing.last_name, this.orderdata.billing.email) : '';
+const billing = this.orderdata.billing || {};
+this.serachInput = newVal
+    ? this.getCustomerDisplayName(billing.first_name, billing.last_name, billing.email)
+    : '';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'orderdata.customer_id'(newVal) {
this.serachInput = newVal ? this.orderdata.billing.first_name + ' ' + this.orderdata.billing.last_name : '';
this.serachInput = newVal ? this.getCustomerDisplayName(this.orderdata.billing.first_name, this.orderdata.billing.last_name, this.orderdata.billing.email) : '';
}
},
'orderdata.customer_id'(newVal) {
const billing = this.orderdata.billing || {};
this.serachInput = newVal
? this.getCustomerDisplayName(billing.first_name, billing.last_name, billing.email)
: '';
}
},
🤖 Prompt for AI Agents
In assets/src/frontend/components/CustomerSearch.vue around lines 228 to 232,
the watcher accesses this.orderdata.billing without checking if billing exists,
which can cause a TypeError if billing is undefined. To fix this, add a
null-check to ensure this.orderdata.billing is defined before accessing its
properties. If billing is missing, set this.serachInput to an empty string or a
safe default to prevent errors and maintain reactivity.

Expand Down Expand Up @@ -287,9 +287,14 @@ export default {
this.$emit( 'onCustomerSelected', {} );
}
},
getCustomerDisplayName(first_name, last_name, email) {
return (first_name?.trim() || last_name?.trim())
? `${(first_name || '').trim()} ${(last_name || '').trim()}`.trim()
: (email || '');
},
selectCustomer( customer ) {
this.$emit( 'onCustomerSelected', customer );
this.serachInput = customer.first_name + ' ' + customer.last_name;
this.serachInput = this.getCustomerDisplayName(customer.first_name, customer.last_name, customer.email);
this.showCustomerResults = false;
},
createCustomer() {
Expand Down Expand Up @@ -318,10 +323,11 @@ export default {

wepos.api.post( wepos.rest.root + wepos.rest.posversion + '/customers', customerData )
.done(response => {
this.serachInput = response.first_name + ' ' + response.last_name;
this.serachInput = this.getCustomerDisplayName(response.first_name, response.last_name, response.email);
this.$emit( 'onCustomerSelected', response );
$contentWrap.unblock();
this.closeNewCustomerModal();
alert( this.__( 'Customer created successfully', 'wepos' ) );
}).fail( response => {
$contentWrap.unblock();
alert( response.responseJSON.message );
Expand Down Expand Up @@ -373,9 +379,8 @@ export default {
} );

var orderdata = JSON.parse( localStorage.getItem( 'orderdata' ) );

if ( orderdata.customer_id != 'undefined' && orderdata.customer_id != 0 ) {
this.serachInput = orderdata.billing.first_name + ' ' + orderdata.billing.last_name;
this.serachInput = this.getCustomerDisplayName(orderdata.billing.first_name, orderdata.billing.last_name, orderdata.billing.email);
}
Comment on lines 381 to 384

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Same undefined-billing guard needed here

orderdata.billing is accessed directly in created(). Mirror the defensive guard added to the watcher to prevent a startup crash.

🤖 Prompt for AI Agents
In assets/src/frontend/components/CustomerSearch.vue around lines 381 to 384,
the code accesses orderdata.billing directly without checking if
orderdata.billing is defined, which can cause a startup crash. Add a defensive
check to ensure orderdata.billing exists before accessing its properties,
similar to the guard used in the watcher, to prevent errors when billing is
undefined.

}
};
Expand Down