Skip to content

Commit

Permalink
Adding configuration options for variant support
Browse files Browse the repository at this point in the history
  • Loading branch information
aldavigdis committed Jul 15, 2024
1 parent 22cd0e7 commit c2d093c
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 31 deletions.
46 changes: 46 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,4 +721,50 @@ public static function set_international_customer_ledger_code(
(string) $value
);
}

public static function get_use_attribute_description(): bool {
return (bool) (
get_option( '1984_woo_dk_use_attribute_description', true )
);
}

public static function set_use_attribute_description( bool $value ): bool {
return update_option(
'1984_woo_dk_use_attribute_description',
(bool) $value
);
}

public static function get_use_attribute_value_description(): bool {
return (bool) (
get_option( '1984_woo_dk_use_attribute_value_description', true )
);
}

public static function set_use_attribute_value_description(
bool $value
): bool {
return update_option(
'1984_woo_dk_use_attribute_value_description',
(bool) $value
);
}

public static function get_product_convertion_to_variation_enabled(): bool {
return (bool) (
get_option(
'1984_woo_dk_product_convertion_to_variation_enabled',
false
)
);
}

public static function set_product_convertion_to_variation_enabled(
bool $value
): bool {
return update_option(
'1984_woo_dk_product_convertion_to_variation_enabled',
(bool) $value
);
}
}
24 changes: 13 additions & 11 deletions src/Hooks/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,20 @@ public function __construct() {
10
);

add_filter(
'bulk_actions-edit-product',
array( __CLASS__, 'register_product_to_variant_bulk_action' ),
10
);
if ( Config::get_product_convertion_to_variation_enabled() ) {
add_filter(
'bulk_actions-edit-product',
array( __CLASS__, 'register_product_to_variant_bulk_action' ),
10
);

add_filter(
'handle_bulk_actions-edit-product',
array( __CLASS__, 'handle_product_to_variant_bulk_action' ),
10,
3
);
add_filter(
'handle_bulk_actions-edit-product',
array( __CLASS__, 'handle_product_to_variant_bulk_action' ),
10,
3
);
}
}

/**
Expand Down
43 changes: 24 additions & 19 deletions src/Hooks/WooProductVariations.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace NineteenEightyFour\NineteenEightyWoo\Hooks;

use NineteenEightyFour\NineteenEightyWoo\Config;
use NineteenEightyFour\NineteenEightyWoo\Import\ProductVariations;
use WC_Product_Variation;

Expand Down Expand Up @@ -38,26 +39,30 @@ public function __construct() {
2
);

add_filter(
'woocommerce_variation_option_name',
array( __CLASS__, 'filter_variation_option_name' ),
10,
1
);

add_filter(
'woocommerce_attribute_label',
array( __CLASS__, 'filter_variation_label' ),
10,
3
);
if ( Config::get_use_attribute_value_description() ) {
add_filter(
'woocommerce_variation_option_name',
array( __CLASS__, 'filter_variation_option_name' ),
10,
1
);

add_filter(
'woocommerce_order_item_display_meta_value',
array( __CLASS__, 'filter_woocommerce_order_meta_value' ),
10,
1
);
}

add_filter(
'woocommerce_order_item_display_meta_value',
array( __CLASS__, 'filter_woocommerce_order_meta_value' ),
10,
1
);
if ( Config::get_use_attribute_description() ) {
add_filter(
'woocommerce_attribute_label',
array( __CLASS__, 'filter_variation_label' ),
10,
3
);
}
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/Rest/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,24 @@ public static function rest_api_callback(
);
}

if ( property_exists( $rest_json, 'use_attribute_description' ) ) {
Config::set_use_attribute_description(
$rest_json->use_attribute_description
);
}

if ( property_exists( $rest_json, 'use_attribute_value_description' ) ) {
Config::set_use_attribute_value_description(
$rest_json->use_attribute_value_description
);
}

if ( property_exists( $rest_json, 'product_convertion_to_variation_enabled' ) ) {
Config::set_product_convertion_to_variation_enabled(
$rest_json->product_convertion_to_variation_enabled
);
}

if (
property_exists( $rest_json, 'fetch_products' ) &&
$rest_json->fetch_products
Expand Down
84 changes: 83 additions & 1 deletion views/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,88 @@ class="regular-text api-key-input"
</tr>
</tbody>
</table>
<h3><?php esc_html_e( 'Variations and Attributes', '1984-dk-woo' ); ?></h3>
<p>
<?php
esc_html_e(
'While the variation and attribute codes from DK are used internally, their values can be displayed as the descriptions that are set for each of them in DK. Here you can also enable the product conversion feature.',
'1984-dk-woo'
);
?>
</p>
<table id="dk-variations-table" class="form-table">
<tbody>
<tr>
<th scope="row" class="column-title column-primary">
</th>
<td>
<input
id="use_attribute_description_label_field"
name="use_attribute_description_label"
type="checkbox"
<?php echo esc_attr( Config::get_use_attribute_description() ? 'checked' : '' ); ?>
/>
<label for="use_attribute_description_label_field">
<?php esc_html_e( 'Display the Attribute Label Description from DK', '1984-dk-woo' ); ?>
</label>
<p class="description">
<?php
esc_html_e(
'If enabled, the code for attribute labels will be replaced with the attribute description from DK. Disable this if you only need the attribute label code.',
'1984-dk-woo'
);
?>
</p>
</td>
</tr>
<tr>
<th scope="row" class="column-title column-primary">
</th>
<td>
<input
id="use_attribute_description_value_field"
name="use_attribute_description_value"
type="checkbox"
<?php echo esc_attr( Config::get_use_attribute_value_description() ? 'checked' : '' ); ?>
/>
<label for="use_attribute_description_value_field">
<?php esc_html_e( 'Display the Attribute Value Description from DK', '1984-dk-woo' ); ?>
</label>
<p class="description">
<?php
esc_html_e(
'If enabled, the code for attribute values will be replaced with the attribute description from DK. Disable this if you only need the attribute value code.',
'1984-dk-woo'
);
?>
</p>
</td>
</tr>
<tr>
<th scope="row" class="column-title column-primary">
</th>
<td>
<input
id="product_conversion_field"
name="product_conversion"
type="checkbox"
<?php echo esc_attr( Config::get_product_convertion_to_variation_enabled() ? 'checked' : '' ); ?>
/>
<label for="product_conversion_field">
<?php esc_html_e( 'Enable Product-to-Variation Conversion', '1984-dk-woo' ); ?>
</label>
<p class="description">
<?php
esc_html_e(
'If enabled, any product can be converted into a variant of anohter as a bulk action. This is a very sharp tool, so only use this one if you know what you are doing.',
'1984-dk-woo'
);
?>
</p>
</td>
</tr>
</tbody>
</table>
<h3><?php esc_html_e( 'Ledger Codes', '1984-dk-woo' ); ?></h3>
<p>
<?php
Expand Down Expand Up @@ -377,7 +459,7 @@ class="regular-text api-key-input"
<p class="description">
<?php
esc_html_e(
'If enabled, an email containing the invoice will be sent to the customer automatically after checkout.',
'If enabled, an email containing the invoice will be sent to the customer automatically after checkout. This uses the DK email functionality, so make sure that email delivery is configured correctly in DK.',
'1984-dk-woo'
);
?>
Expand Down

0 comments on commit c2d093c

Please sign in to comment.