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

Using case-insensitive string comparisons using mb_strtolower #195

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function set_rate(
return self::invalid_currency_code_error( $currency );
}

$option_name = '1984_woo_dk_currency_rate_' . strtolower( $currency );
$option_name = '1984_woo_dk_currency_rate_' . mb_strtolower( $currency );

$float_value = (float) $rate;

Expand All @@ -62,7 +62,7 @@ public static function get_rate(
return self::invalid_currency_code_error( $currency );
}

$option_name = '1984_woo_dk_currency_rate_' . strtolower( $currency );
$option_name = '1984_woo_dk_currency_rate_' . mb_strtolower( $currency );

$rate = get_option( $option_name, 0 );

Expand Down Expand Up @@ -105,7 +105,7 @@ public static function convert(
}

$from_rate = get_option(
'1984_woo_dk_currency_rate_' . strtolower( $from ),
'1984_woo_dk_currency_rate_' . mb_strtolower( $from ),
);

if ( ! $from_rate ) {
Expand All @@ -124,7 +124,7 @@ public static function convert(
}

$to_rate = get_option(
'1984_woo_dk_currency_rate_' . strtolower( $to )
'1984_woo_dk_currency_rate_' . mb_strtolower( $to )
);

if ( ! $to_rate ) {
Expand Down
30 changes: 16 additions & 14 deletions src/Import/ProductVariations.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ public static function attributes_to_woocommerce_variation_attributes(
return array();
}

$lower_case_code = mb_strtolower( $code );

$variations = self::get_variations();

$attributes = $variations[ $code ]->attributes;
$attributes = $variations[ $lower_case_code ]->attributes;

$woocommerce_variation_attributes = array();

foreach ( $attributes as $code => $attribute ) {
$woocommerce_variation_attributes[ strtolower( $code ) ] = array_keys(
$woocommerce_variation_attributes[ $lower_case_code ] = array_keys(
$attribute->values
);
}
Expand Down Expand Up @@ -313,7 +315,7 @@ public static function get_attribute_from_dk(
$code = $object->CODE;
return (object) array(
'id' => $record_id,
'code' => strtolower( $code ),
'code' => mb_strtolower( $code ),
'description' => $description,
'values' => self::get_variation_attributes( $record_id ),
);
Expand Down Expand Up @@ -381,8 +383,8 @@ public static function get_variation_attributes_from_dk(
$attributes = array();

foreach ( $result->data as $a ) {
$code = strtolower( $a->HEADCODE );
$code_key = strtolower( $code );
$code = mb_strtolower( $a->HEADCODE );
$code_key = mb_strtolower( $code );

$attributes[ $code ] = (object) array(
'code' => $code,
Expand All @@ -406,7 +408,7 @@ public static function get_variation_attributes_from_dk(
public static function get_attribute_name( string $code ): string {
$attribute_values = self::get_attribute_values();

$key = strtolower( $code );
$key = mb_strtolower( $code );

if ( ! key_exists( $key, $attribute_values ) ) {
return $code;
Expand Down Expand Up @@ -469,8 +471,8 @@ public static function get_attribute_values_from_dk(): array {
$name = $code;
}

$values[ strtolower( $code ) ] = (object) array(
'code' => strtolower( $code ),
$values[ mb_strtolower( $code ) ] = (object) array(
'code' => mb_strtolower( $code ),
'name' => $name,
);
}
Expand All @@ -491,26 +493,26 @@ public static function parse_variations_json( array $variation_json ): array {

foreach ( $variation_json as $vj ) {
$variation = array();
$code = strtolower( $vj->CODE );
$code = mb_strtolower( $vj->CODE );
$description = $vj->DESCRIPTION;

$variation['skus'] = self::get_product_skus_by_variation_from_dk(
$code
);

$variations[ $code ] = array(
'code' => strtolower( $code ),
'code' => mb_strtolower( $code ),
'description' => $description,
);

if ( property_exists( $vj, 'SUBGROUP1' ) ) {
$variation['attributes'][ strtolower( $vj->SUBGROUP1 ) ] =
self::get_attribute( strtolower( $vj->SUBGROUP1 ) );
$variation['attributes'][ mb_strtolower( $vj->SUBGROUP1 ) ] =
self::get_attribute( mb_strtolower( $vj->SUBGROUP1 ) );
}

if ( property_exists( $vj, 'SUBGROUP2' ) ) {
$variation['attributes'][ strtolower( $vj->SUBGROUP2 ) ] =
self::get_attribute( strtolower( $vj->SUBGROUP2 ) );
$variation['attributes'][ mb_strtolower( $vj->SUBGROUP2 ) ] =
self::get_attribute( mb_strtolower( $vj->SUBGROUP2 ) );
}

$variations[ $code ] = (object) $variation;
Expand Down
23 changes: 16 additions & 7 deletions src/Import/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,24 @@ public static function json_to_new_product(
return false;
}

if ( strtolower( Config::get_shipping_sku() ) === strtolower( $json_object->ItemCode ) ) {
if (
mb_strtolower( Config::get_shipping_sku() ) ===
mb_strtolower( $json_object->ItemCode )
) {
return false;
}

if ( strtolower( Config::get_cost_sku() ) === strtolower( $json_object->ItemCode ) ) {
if (
mb_strtolower( Config::get_cost_sku() ) ===
mb_strtolower( $json_object->ItemCode )
) {
return false;
}

if ( ! $json_object->ShowItemInWebShop && ! Config::get_import_nonweb_products() ) {
if (
! $json_object->ShowItemInWebShop &&
! Config::get_import_nonweb_products()
) {
return false;
}

Expand Down Expand Up @@ -730,13 +739,13 @@ public static function merge_variations(
}
$variation = array(
'quantity' => (float) $v->Quantity,
'attribute_1' => strtolower( $attribute_names[0] ),
'code_1' => strtolower( $v->Code ),
'attribute_1' => mb_strtolower( $attribute_names[0] ),
'code_1' => mb_strtolower( $v->Code ),
);

if ( property_exists( $v, 'Code2' ) ) {
$variation['attribute_2'] = strtolower( $attribute_names[1] );
$variation['code_2'] = strtolower( $v->Code2 );
$variation['attribute_2'] = mb_strtolower( $attribute_names[1] );
$variation['code_2'] = mb_strtolower( $v->Code2 );
}

$variations_array[] = (object) $variation;
Expand Down
Loading