Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coupons & Fees - Relationship Table #3257

Open
wants to merge 17 commits into
base: bucket/order_modifiers_coupon_fees
Choose a base branch
from

Conversation

redscar
Copy link
Contributor

@redscar redscar commented Sep 25, 2024

Summary of Changes:

This PR introduces the integration of the relationship table into the order modifiers system. The work primarily focuses on ensuring that fee modifiers and their relationships (such as venues and organizers) are properly handled and updated in the database, while also improving overall flexibility and structure.

Key Changes:

  • Controller Updates:

    • Updated the Controller.php to handle the new relationship logic, integrating with the newly created Order_Modifier_Relationships class and ensuring proper flow when relationships are added or deleted.
  • Order Modifier Relationships:

    • Introduced and integrated the Order_Modifier_Relationships class, which is responsible for managing the relationships between order modifiers (such as fees) and entities like venues or organizers.
    • Added logic to handle CRUD operations for these relationships, ensuring they can be created, updated, or deleted alongside the modifiers themselves.
  • Order Modifier DTO (Data Transfer Object):

    • Updated the Order_Modifier_DTO class to include relationship data, allowing for smooth data transfer between various layers of the application, and simplifying the handling of related entities.
  • Name Changes & Refactoring:

    • Renamed the Modifier_Settings class to Modifier_Admin_Handler to better reflect its role in handling admin-related actions, such as managing order modifier settings and actions in the admin UI.
    • Refactored and renamed several methods for clarity and consistency across classes.
  • Modifier_Abstract & Fee Class Updates:

    • Added relationship logic to the Modifier_Abstract class, which serves as the base for handling different types of modifiers.
    • In the Fee class, implemented logic to manage specific fee-related operations, including how the relationships with venues, organizers, and tickets are handled when a fee is created or updated.

Additional Updates:

  • Various other files were updated to integrate the new relationship table and refactor existing logic for cleaner code and more maintainable architecture.

@redscar redscar added the code review Status: requires a code review. label Sep 25, 2024
if ( ! $this->has_index( $index_name ) ) {
// Prepare the SQL for adding an index.
$sql = $wpdb->prepare(
"ALTER TABLE `$table_name` ADD INDEX `%s` ( $columns )",
Copy link
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.DB.PreparedSQL.InterpolatedNotPrepared
Use placeholders and $wpdb->prepare(); found interpolated variable $table_name at "ALTER TABLE $table_name ADD INDEX %s ( $columns )"

if ( ! $this->has_index( $index_name ) ) {
// Prepare the SQL for adding an index.
$sql = $wpdb->prepare(
"ALTER TABLE `$table_name` ADD INDEX `%s` ( $columns )",
Copy link
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.DB.PreparedSQL.InterpolatedNotPrepared
Use placeholders and $wpdb->prepare(); found interpolated variable $columns at "ALTER TABLE $table_name ADD INDEX %s ( $columns )"

*
* @return Order_Modifier_Relationships_DTO The DTO instance.
*/
public static function fromObject( $object ): self {
Copy link
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound
It is recommended not to use reserved keyword "object" as function parameter name. Found: $object

</select>
<p>Select a group to apply this fee to tickets automatically. This can be overridden on a per ticket
basis during ticket creation.</p>
</div>

<?php
// @todo redscar - This needs to be refactored.
$posts = get_posts(
Copy link
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.WP.GlobalVariablesOverride.Prohibited
Overriding WordPress globals is prohibited. Found assignment to $posts


<select name="organizer_list">
<option value=""><?php esc_html_e( 'Select an organizer', 'event-tickets' ); ?></option>
<?php foreach ( $posts as $post ) : ?>
Copy link
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
WordPress.WP.GlobalVariablesOverride.Prohibited
Overriding WordPress globals is prohibited. Found assignment to $post

…relationship_table' into feature/et_2189_order_modifiers_relationship_table
*
* @return static
*/
public static function fromQueryBuilderObject( $object ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound
It is recommended not to use reserved keyword "object" as function parameter name. Found: $object

@redscar
Copy link
Contributor Author

redscar commented Sep 25, 2024

I had to disable foreign key checks for the ft_ct1_migrationwhen truncating the posts table.

@redscar redscar requested a review from JPry September 25, 2024 13:58
@redscar redscar marked this pull request as ready for review September 25, 2024 13:58
$builder = new ModelQueryBuilder( Order_Modifier::class );

return $builder->from( Table::table_name( false ), 'orders' )
->select( 'orders.*' )
Copy link
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
Universal.WhiteSpace.PrecisionAlignment.Found
Found precision alignment of 3 spaces.


return $builder->from( Table::table_name( false ), 'orders' )
->select( 'orders.*' )
->innerJoin( "$meta_table as meta", 'meta.order_modifier_id', 'orders.id' )
Copy link
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
Universal.WhiteSpace.PrecisionAlignment.Found
Found precision alignment of 3 spaces.

return $builder->from( Table::table_name( false ), 'orders' )
->select( 'orders.*' )
->innerJoin( "$meta_table as meta", 'meta.order_modifier_id', 'orders.id' )
->where( 'modifier_type', $modifier_type )
Copy link
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
Universal.WhiteSpace.PrecisionAlignment.Found
Found precision alignment of 3 spaces.

->select( 'orders.*' )
->innerJoin( "$meta_table as meta", 'meta.order_modifier_id', 'orders.id' )
->where( 'modifier_type', $modifier_type )
->where( 'meta.meta_key', $meta_key )
Copy link
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
Universal.WhiteSpace.PrecisionAlignment.Found
Found precision alignment of 3 spaces.

->innerJoin( "$meta_table as meta", 'meta.order_modifier_id', 'orders.id' )
->where( 'modifier_type', $modifier_type )
->where( 'meta.meta_key', $meta_key )
->where( 'meta.meta_value', $meta_value )
Copy link
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
Universal.WhiteSpace.PrecisionAlignment.Found
Found precision alignment of 3 spaces.

->where( 'modifier_type', $modifier_type )
->where( 'meta.meta_key', $meta_key )
->where( 'meta.meta_value', $meta_value )
->getAll();
Copy link
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
Universal.WhiteSpace.PrecisionAlignment.Found
Found precision alignment of 3 spaces.

@redscar redscar self-assigned this Sep 26, 2024
@@ -14,12 +14,13 @@
use TEC\Common\StellarWP\Schema\Register as Schema_Register;
use TEC\Common\StellarWP\Schema\Config as Schema_Config;
use TEC\Common\StellarWP\DB\DB;
use TEC\Common\StellarWP\Schema\Tables\Contracts\Table;
use TEC\Tickets\Order_Modifiers\Custom_Tables\Order_Modifier_Relationships;
Copy link
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse
Type TEC\Tickets\Order_Modifiers\Custom_Tables\Order_Modifier_Relationships is not used in this file.

use TEC\Tickets\Order_Modifiers\Custom_Tables\Order_Modifiers;
use TEC\Tickets\Order_Modifiers\Custom_Tables\Order_Modifiers_Meta;
use TEC\Tickets\Order_Modifiers\Modifiers\Coupon;
use TEC\Tickets\Order_Modifiers\Modifiers\Fee;
use TEC\Tickets\Order_Modifiers\Modifiers\Modifier_Strategy_Interface;
use TEC\Tickets\Order_Modifiers\Admin\Classic_Modifier;
Copy link
Contributor

Choose a reason for hiding this comment

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

[phpcs] reported by reviewdog 🐶
SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse
Type TEC\Tickets\Order_Modifiers\Admin\Classic_Modifier is not used in this file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code review Status: requires a code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants