Skip to content

Add YCom address forms for invoice and delivery addresses - #245

Merged
AWqxKAWERbXo merged 9 commits into
mainfrom
copilot/add-invoice-address-fragment
Oct 19, 2025
Merged

Add YCom address forms for invoice and delivery addresses#245
AWqxKAWERbXo merged 9 commits into
mainfrom
copilot/add-invoice-address-fragment

Conversation

Copilot AI commented Oct 19, 2025

Copy link
Copy Markdown
  • Create main invoice-address.php fragment in /fragments/warehouse/bootstrap5/
  • Create ycom/invoice-address-form.php fragment with YForm for invoice address editing
  • Create main delivery-address.php fragment in /fragments/warehouse/bootstrap5/
  • Create ycom/delivery-address-form.php fragment with YForm for delivery address editing
  • Use CustomerAddress field constants instead of hardcoded strings
  • Query and prefill form with current logged-in YCom user's data
  • Show success message after form save
  • Add proper validation and action fields
  • Replace translate: prefixes with Warehouse::getLabel() for frontend text
  • Add label definitions to package.yml
  • Add label fields to pages/settings.label.php for backend editing
  • Keep translate: only for backend validation messages
  • Use simpler setActionField('showtext') approach for success messages

Summary

All frontend labels now use Warehouse::getLabel() instead of translate: prefixes. New labels added:

  • label_address_name - Name field
  • label_address_street - Street field
  • label_address_company - Company field
  • label_address_save - Save button
  • label_address_saved_successfully - Success message
  • label_ycom_not_logged_in - Not logged in warning

Labels are defined in package.yml with German defaults and can be edited in the backend settings page.

Success messages now use YForm's built-in showtext action field, which automatically displays the message only when the form is successfully saved.

Original prompt

This section details on the original issue you should resolve

<issue_title>Fragment for YForm YCom form to edit it's own invoice address</issue_title>
<issue_description>1. Create a new invoice-address.php in /fragments/bootstrap5/ so it can be selected via module, referencing another new fragment fragments/bootstrap5/ycom/invoice-address-form.php that contains a form like this:

$current_ycom_user_id = ...; // find out

$yform = new rex_yform();
$yform->setObjectparams('form_name', 'table-rex_warehouse_customer_address');
$yform->setObjectparams('form_action',rex_getUrl('REX_ARTICLE_ID'));
$yform->setObjectparams('form_ytemplate', 'bootstrap5,bootstrap');
$yform->setObjectparams('form_showformafterupdate', 1);
$yform->setObjectparams('real_field_names', true);

$yform->setValueField('hidden', ['ycom_user_id','translate:warehouse_customer_address.ycom_user_id',$current_ycom_user_id]);
$yform->setValueField('hidden', ['type','translate:warehouse_customer_address.type','FriendsOfRedaxo\Warehouse\CustomerAddress::getTypeOptions','0','0','','','','','','','','','0']);
$yform->setValidateField('empty', ['type','translate:warehouse_customer_address.validate.empty.type']);
$yform->setValueField('text', ['company','translate:warehouse_customer_address.company','','0']);
$yform->setValidateField('empty', ['company','translate:warehouse_customer_address.validate.empty.company']);
$yform->setValueField('text', ['name','translate:warehouse_customer_address.name','','0']);
$yform->setValidateField('empty', ['name','translate:warehouse_customer_address.validate.empty.name']);
$yform->setValueField('text', ['street','translate:warehouse_customer_address.street','','0']);
$yform->setValidateField('empty', ['street','translate:warehouse_customer_address.validate.empty.street']);
$yform->setValueField('text', ['zip','translate:warehouse_customer_address.zip','','0']);
$yform->setValidateField('empty', ['zip','translate:warehouse_customer_address.validate.empty.zip']);
$yform->setValueField('text', ['city','translate:warehouse_customer_address.city','','0']);
$yform->setValidateField('empty', ['city','translate:warehouse_customer_address.validate.empty.city']);
$yform->setValueField('text', ['country','translate:warehouse_customer_address.country','','0']);
$yform->setValidateField('unique', ['ycom_user_id,type,name,zip,street,city','translate:warehouse_customer_address.validate.unique.ycom_user_id_and_type','','0']);
$yform->setValidateField('unique', ['ycom_user_id,type','translate:warehouse_customer_address.validate.unique.ycom_user_id_and_type','','0']);
$yform->setValueField('warehouse_marker', ['favorite_marker','translate:warehouse_customer_address.favorite_marker']);

$yform->setActionField('tpl2email', ['emailtemplate', 'emailfieldname/email@example.org']);
echo $yform->getForm();

But you

  • you need to query the data from the current logged in ycom user
  • you need and prefill the form with the right information / load the correct dataset

This example might help for the task

$dataset = null;
if ($id) {
    $dataset = rex_yform_manager_table::get('rex_warehouse_customer_address')->query()->where(...)->find();
}

$form = new rex_yform();
$form->setObjectparams('form_action', rex_getUrl());
$form->setObjectparams('form_name', 'myform');
if ($dataset) {
    $form->setFormData($dataset->getData());
}

$form->setValueField('text', ['name', 'Name']);
// ... add more fields as needed

echo $form->getForm();
  1. you need to repeat the step 1 also for the rex_warehouse_customer_address as there are two types: one for invoice address and one for delivery address.

  2. show a success message if the form was saved

  3. replace hardcoded field names with the ones that are found in the Address class</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #244


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai

coderabbitai Bot commented Oct 19, 2025

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 3 commits October 19, 2025 22:11
Co-authored-by: randalex-de <3855487+randalex-de@users.noreply.github.com>
Co-authored-by: randalex-de <3855487+randalex-de@users.noreply.github.com>
Co-authored-by: randalex-de <3855487+randalex-de@users.noreply.github.com>
Copilot AI changed the title [WIP] Add fragment for YForm YCom to edit invoice address Add YCom address forms for invoice and delivery addresses Oct 19, 2025
Copilot AI requested a review from AWqxKAWERbXo October 19, 2025 22:17
@AWqxKAWERbXo

Copy link
Copy Markdown

@copilot that looks very good. Only exception: Don't use translate: prefix for frontend text. This is preserved for REDAXO backend translation. Use the label class of Warehouse itself and add labels if needed to the text configuration page in /pages/ as well as german default labels in package.yml.

… to package.yml

Co-authored-by: randalex-de <3855487+randalex-de@users.noreply.github.com>

Copilot AI commented Oct 19, 2025

Copy link
Copy Markdown
Author

@copilot that looks very good. Only exception: Don't use translate: prefix for frontend text. This is preserved for REDAXO backend translation. Use the label class of Warehouse itself and add labels...

Done! Replaced all frontend translate: prefixes with Warehouse::getLabel() calls. Added new labels to package.yml with German defaults and to pages/settings.label.php for backend editing. Backend validation messages still use translate: as appropriate. (commit 048081e → latest)

@AWqxKAWERbXo
AWqxKAWERbXo marked this pull request as ready for review October 19, 2025 22:27
Copilot AI review requested due to automatic review settings October 19, 2025 22:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds YCom user address management functionality by creating form fragments for invoice and delivery addresses. Users can now edit their own billing and shipping addresses through dedicated frontend forms that integrate with YCom authentication.

Key Changes:

  • Added YForm-based address editing forms for invoice (billing) and delivery (shipping) addresses with YCom user integration
  • Introduced CustomerAddress field constants for type-safe database column references
  • Replaced hardcoded translate: prefixes with Warehouse::getLabel() calls for frontend labels, with new label definitions in package.yml and backend editing support

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
fragments/warehouse/bootstrap5/invoice-address.php Main fragment that checks for backend context and required add-ons, then delegates to the invoice address form fragment
fragments/warehouse/bootstrap5/delivery-address.php Main fragment that checks for backend context and required add-ons, then delegates to the delivery address form fragment
fragments/warehouse/bootstrap5/ycom/invoice-address-form.php YForm-based form for editing invoice/billing addresses with YCom user authentication, data prefilling, and success message display
fragments/warehouse/bootstrap5/ycom/delivery-address-form.php YForm-based form for editing delivery/shipping addresses with YCom user authentication, data prefilling, and success message display
package.yml Added default German label values for address fields, save button, success message, and YCom authentication warning
pages/settings.label.php Added label configuration fields to backend settings page for the new address-related labels

Comment on lines +80 to +81
echo $form_output;
}

Copilot AI Oct 19, 2025

Copy link

Choose a reason for hiding this comment

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

The success message logic appears inverted. When form_show_submit is false (after successful submission), both the success message and form are displayed. However, when form_show_submit is true (initial display), only the form is shown without the success message. Consider checking YForm's actual behavior: typically, after a successful submission, YForm may reset form_show_submit or use a different mechanism to indicate success. This logic should be verified against YForm's documented behavior or refactored to use YForm's success detection mechanism correctly.

Suggested change
echo $form_output;
}
}

Copilot uses AI. Check for mistakes.
} else {
// Form was submitted successfully
echo '<div class="alert alert-success">' . Warehouse::getLabel('address_saved_successfully') . '</div>';
echo $form_output;

Copilot AI Oct 19, 2025

Copy link

Choose a reason for hiding this comment

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

The success message logic appears inverted. When form_show_submit is false (after successful submission), both the success message and form are displayed. However, when form_show_submit is true (initial display), only the form is shown without the success message. Consider checking YForm's actual behavior: typically, after a successful submission, YForm may reset form_show_submit or use a different mechanism to indicate success. This logic should be verified against YForm's documented behavior or refactored to use YForm's success detection mechanism correctly.

Suggested change
echo $form_output;

Copilot uses AI. Check for mistakes.
@AWqxKAWERbXo

Copy link
Copy Markdown

@copilot a much more simple approach might be to use this action

$yform->setActionField('showtext', array("Hallo das ist Redaxo", "<p>", "</p>", "0"));

which will only be shown if successfully sent/saved.

Co-authored-by: randalex-de <3855487+randalex-de@users.noreply.github.com>

Copilot AI commented Oct 19, 2025

Copy link
Copy Markdown
Author

@copilot a much more simple approach might be to use this action

...

Implemented! Replaced the manual success message check with setActionField('showtext', ...) which automatically displays only on successful save. Much simpler approach. (commit 4940f7e → latest)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread fragments/warehouse/bootstrap5/ycom/invoice-address-form.php Outdated
Comment thread fragments/warehouse/bootstrap5/ycom/delivery-address-form.php Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@AWqxKAWERbXo
AWqxKAWERbXo merged commit 8389c17 into main Oct 19, 2025
1 check failed
@AWqxKAWERbXo
AWqxKAWERbXo deleted the copilot/add-invoice-address-fragment branch October 19, 2025 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fragment for YForm YCom form to edit it's own invoice address

3 participants