Skip to content

Commit

Permalink
For easier merge
Browse files Browse the repository at this point in the history
  • Loading branch information
iverok committed Nov 27, 2024
1 parent 7bf0a5e commit 5854c79
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 141 deletions.
41 changes: 17 additions & 24 deletions Blocks/woo-vipps-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,30 @@

// This is the new script to register blocks built into ./dist. At this time only the vipps-badge block. LP 19.11.2024

/**
* Init hooks and inline script for the block vipps-badge. LP 14.11.2024.
*
* @return void
*/
function vipps_badge_block_hooks() {
add_action('init', function () {
add_action('init', function () {
register_block_type(__DIR__ . '/dist/vipps-badge');
});
});

// Inject block config variables to vipps-badge editor script. LP 15.11.2024
add_action('enqueue_block_editor_assets', function () {
// Inject block config variables to vipps-badge editor script. LP 15.11.2024
add_action('enqueue_block_editor_assets', function () {
$vipps = Vipps::instance();
$variants = $variants = [
['label' => __('White', 'woo-vipps'), 'value' => 'white'],
['label' => __('Grey', 'woo-vipps'), 'value' => 'grey'],
['label' => __('Filled', 'woo-vipps'), 'value' => 'filled'],
['label' => __('Light', 'woo-vipps'), 'value' => 'light'],
['label' => __('Purple', 'woo-vipps'), 'value' => 'purple']];
['label' => __('White', 'woo-vipps'), 'value' => 'white'],
['label' => __('Grey', 'woo-vipps'), 'value' => 'grey'],
['label' => __('Filled', 'woo-vipps'), 'value' => 'filled'],
['label' => __('Light', 'woo-vipps'), 'value' => 'light'],
['label' => __('Purple', 'woo-vipps'), 'value' => 'purple']];

// Set a default language for the vipps-badge. LP 21.11.2024
$store_language = substr(get_bloginfo('language'), 0, 2);
if ($store_language == 'nb' || $store_language == 'nn') {
$store_language = 'no';
$store_language = 'no';
}
if ($store_language == 'da') {
$store_language = 'dk';
$store_language = 'dk';
}
if (!in_array($store_language, ['en', 'no', 'dk', 'fi'])) {
$store_language = 'en';
$store_language = 'en';
} // english default fallback

$block_config = [
Expand All @@ -50,10 +44,9 @@ function vipps_badge_block_hooks() {
],
];

wp_add_inline_script('woo-vipps-vipps-badge-editor-script',
'const injectedVippsBadgeBlockConfig = ' . json_encode($block_config),
'before');
});
}
wp_add_inline_script('woo-vipps-vipps-badge-editor-script',
'const injectedVippsBadgeBlockConfig = ' . json_encode($block_config),
'before');
});


vipps_badge_block_hooks();
99 changes: 2 additions & 97 deletions Vipps.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,29 +398,6 @@ public function maybe_add_vipps_badge_feature () {
}


// Comment out vipps-senere stuff. LP 18.11.2024
// $price = 0;
// $supported_currencies = ['NOK'];
// $currency = get_woocommerce_currency();
// if ($product && in_array($currency, $supported_currencies)) {
// // Currently only supports NOK! 2022-11-11 IOK
// $price = $product->get_price();
// $price = round($price * 100);
// $attr .= " amount ='". $price. "' ";
// }

// $showlater = @$badge_options['later'] && $price>=intval(@$badge_options['minLater']);
// $showlaterforthis = $product->get_meta('_vipps_badge_pay_later', true);
// if ($showlaterforthis == 'no') {
// $showlater = false;
// } else if ($showlaterforthis == 'later') {
// $showlater = true;
// }

// if (apply_filters('woo_vipps_product_badge_show_later', $showlater, $product)) {
// $attr .= " vipps-senere='" . sanitize_title($badge_options['later']) . "' ";
// }

$lang = $this->get_customer_language();
if ($lang) {
$attr .= " language='". $lang . "' ";
Expand Down Expand Up @@ -748,9 +725,7 @@ public function badge_menu_page () {
<vipps-mobilepay-badge id="vipps-badge-demo"
<?php if (@$badge_options['brand']) echo ' brand="' . esc_attr(strtolower($this->get_payment_method_name())) . '" ' ?>
<?php if (@$badge_options['variant']) echo ' variant="' . esc_attr($badge_options['variant']) . '" ' ?>
<?php /* Comment out vipps-later stuff. LP 18.11.2024.
if (@$badge_options['later']) echo ' vipps-senere="' . esc_attr($badge_options['later']) . '" ' */ ?>
></vipps-mobilepay-badge>
></vipps-mobilepay-badge>
</p>

<div>
Expand All @@ -765,21 +740,6 @@ public function badge_menu_page () {
<?php endforeach; ?>
</select>

<!-- Comment out vipps-senere stuff. LP 18.11.2024 -->
<?php /*
<div>
<label for="vippsLater"><?php echo sprintf(__('Support "%1$s Later"', 'woo-vipps'), Vipps::CompanyName()); ?></label>
<input type="hidden" name="later" value="0" />
<input onChange='changeLater();' <?php if (@$badge_options['later']) echo " checked "; ?> value="1" type="checkbox" id="vippsLater" name="later" /><div style="display:inline-block"><?php echo sprintf(__("Check this if your store supports %1\$s Senere and you want the specialized badge for that", 'woo-vipps'), Vipps::CompanyName()); ?>
</div>
<div>
<label for="vippsLater"><?php echo sprintf(__('Minimum price for "%1$s Later""', 'woo-vipps'), Vipps::CompanyName()); ?></label>
<input style="text-align:right; width: 8rem" type="text" pattern="[0-9]+" name="minLater"
<?php if (@$badge_options['minLater']) echo 'value="' . intval($badge_options['minLater']) . '"'; ?>
/>
</div>
*/ ?>

<input type="hidden" name="brand" value="<?php echo strtolower($this->get_payment_method_name())?>" />

<div>
Expand All @@ -794,8 +754,7 @@ public function badge_menu_page () {
<h2><?php _e('Shortcodes', 'woo-vipps'); ?> </h2>
<p><?php echo sprintf(__('If you need to add a %1$s badge on a specific page, footer, header and so on, and you cannot use the Gutenberg Block provided for this, you can either add the %1$s Badge manually (as <a href="%2$s" nofollow rel=nofollow target=_blank>documented here</a>) or you can use the shortcode.', 'woo-vipps'), Vipps::CompanyName(), "https://developer.vippsmobilepay.com/docs/knowledge-base/design-guidelines/on-site-messaging/"); ?></p>
<br><?php _e("The shortcode looks like this:", 'woo-vipps')?><br>
<pre>[vipps-mobilepay-badge <!--badge={vipps|mobilepay}<br> -->variant={white|filled|light|grey|purple}<br> language={en|no|fi|dk}<!-- Comment out vipps-senere stuff. LP 18.11.2024
<br> amount={amount in minor units}<br> vipps-senere={false|true}-->]</pre><br>
<pre>[vipps-mobilepay-badge variant={white|filled|light|grey|purple}<br> language={en|no|fi|dk} ] </pre><br>
<?php _e("Please refer to the documentation for the meaning of the parameters.", 'woo-vipps'); ?></br>
<?php _e("The brand will be automatically applied.", 'woo-vipps'); ?>
</p>
Expand All @@ -814,21 +773,6 @@ function changeVariant() {
badge.remove();
holder.appendChild(newbadge);
}
// Comment out vipps-senere stuff. LP 18.11.2024
// function changeLater() {
// let badge = document.getElementById('vipps-badge-demo');
// let later = document.getElementById('vippsLater').checked;
// if (later) {
// badge.setAttribute('vipps-senere', true);
// } else {
// badge.removeAttribute('vipps-senere');
// }
// let holder = document.getElementById('badgeholder');
// let newbadge = badge.cloneNode();
// badge.remove();
// holder.appendChild(newbadge);
// }

</script>
<?php
}
Expand All @@ -853,23 +797,13 @@ public function update_badge_settings () {
if (isset($_POST['variant'])) {
$current['variant'] = sanitize_title($_POST['variant']);
}
// Comment out vipps-senere stuff. LP 18.11.2024
// if (isset($_POST['later'])) {
// $current['later'] = intval($_POST['later']);
// }
// if (isset($_POST['minLater'])) {
// $current['minLater'] = intval($_POST['minLater']);
// }

update_option('vipps_badge_options', $current);
wp_safe_redirect(admin_url("admin.php?page=vipps_badge_menu"));
exit();
}

public function vipps_mobilepay_badge_shortcode($atts) {
// comment out vipps-senere stuff. LP 18.11.2024
// $args = shortcode_atts( array('id'=>'', 'class'=>'', 'variant' => '','language'=>'','amount' => '', 'vipps-senere'=>''), $atts );

$args = shortcode_atts( array('id'=>'', 'class'=>'', 'brand' => '', 'variant' => '','language'=>''), $atts );

$variant = in_array($args['variant'], ['orange', 'light-orange', 'grey','white', 'purple', 'filled', 'light']) ? $args['variant'] : "";
Expand All @@ -896,23 +830,16 @@ public function vipps_mobilepay_badge_shortcode($atts) {

// legacy vipps_badge shortcode. LP 19.11.2024
public function vipps_badge_shortcode($atts) {
// comment out vipps-senere stuff. LP 19.11.2024
// $args = shortcode_atts( array('id'=>'', 'class'=>'', 'variant' => '','language'=>'','amount' => '', 'vipps-senere'=>''), $atts );

$args = shortcode_atts( array('id'=>'', 'class'=>'','variant' => '','language'=>''), $atts );

$variant = in_array($args['variant'], ['orange', 'light-orange', 'grey','white', 'purple']) ? $args['variant'] : "";
$language = in_array($args['language'], ['en','no', 'dk', 'fi']) ? $args['language'] : $this->get_customer_language();
// $amount = intval($args['amount']);
// $later = $args['vipps-senere'];
$id = sanitize_title($args['id']);
$class = sanitize_text_field($args['class']);

$attributes = [];
if ($variant) $attributes['variant'] = $variant;
if ($language) $attributes['language'] = $language;
// if ($amount) $attributes['amount'] = $amount;
// if ($later) $attributes['vipps-senere'] = 1;
if ($id) $attributes['id'] = $id;
if ($class) $attributes['class'] = $class;

Expand Down Expand Up @@ -1428,11 +1355,6 @@ public function process_product_meta ($id, $post) {
update_post_meta($id, '_vipps_show_badge', sanitize_text_field($_POST['woo_vipps_show_badge']));
}

// Comment out vipps-senere stuff. LP 18.11.2024
// if (isset($_POST['woo_vipps_badge_pay_later'])) {
// update_post_meta($id, '_vipps_badge_pay_later', sanitize_text_field($_POST['woo_vipps_badge_pay_later']));
// }

// This is for the shareable links.
if (isset($_POST['woo_vipps_shareable_delenda'])) {
$delenda = array_map('sanitize_text_field',$_POST['woo_vipps_shareable_delenda']);
Expand Down Expand Up @@ -1514,9 +1436,6 @@ public function product_options_vipps_badges() {
echo "<h4></div>";
$showbadge = sanitize_text_field(get_post_meta( get_the_ID(), '_vipps_show_badge', true));

// Comment out vipps-senere stuff. LP 18.11.2024
// $later = sanitize_text_field(get_post_meta( get_the_ID(), '_vipps_badge_pay_later', true));

woocommerce_wp_select(
array(
'id' => 'woo_vipps_show_badge',
Expand All @@ -1533,20 +1452,6 @@ public function product_options_vipps_badges() {
'value' => $showbadge
)
);

// Comment out vipps-senere stuff. LP 18.11.2024
// woocommerce_wp_select(
// array(
// 'id' => 'woo_vipps_badge_pay_later',
// 'label' => sprintf(__( 'Override %1$s Later', 'woo-vipps' ), $this->get_payment_method_name()),
// 'options' => array(
// '' => __('Default setting', 'woo-vipps'),
// 'later' => sprintf(__('Use %1$s Later', 'woo-vipps'), $this->get_payment_method_name()),
// 'no' => sprintf(__('Do not use %1$s Later', 'woo-vipps'), $this->get_payment_method_name()),
// ),
// 'value' => $later
// )
// );
echo "</div>";

}
Expand Down
20 changes: 0 additions & 20 deletions VippsWCProductEditorV2.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,6 @@ public function init_woo_vipps_product_tab($general_group)
]
);

// Comment out vipps-senere stuff. LP 18.11.2024.
// $badges_section->add_block(
// [
// 'id' => 'woo-vipps-overrides-later',
// 'blockName' => 'woocommerce/product-select-field',
// 'order' => 3,
// 'attributes' => [
// 'label' => sprintf(__('Override %1$s Later', 'woo-vipps'), $payment_method_name),
// 'property' => 'meta_data._vipps_badge_pay_later',
// 'autoFocus' => false,
// 'help' => __('Choose if this product should use Vipps Later', 'woo-vipps'),
// 'options' => array(
// ['value' => '', 'label' => __('Default setting', 'woo-vipps')],
// ['value' => 'later', 'label' => sprintf(__('Use %1$s Later', 'woo-vipps'), $payment_method_name)],
// ['value' => 'no', 'label' => sprintf(__('Do not use %1$s Later', 'woo-vipps'), $payment_method_name)],
// ),
// ],
// ]
// );

if ($payment_method_name == "Vipps") {
// Buy now section
$buy_now_section = $gr->add_section(
Expand Down

0 comments on commit 5854c79

Please sign in to comment.