Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
iverok committed Dec 9, 2024
2 parents 3261d00 + 80769d9 commit cb7d990
Show file tree
Hide file tree
Showing 28 changed files with 5,293 additions and 5,718 deletions.
45 changes: 0 additions & 45 deletions Blocks/Products/js/editor.js

This file was deleted.

48 changes: 0 additions & 48 deletions Blocks/Products/js/index.js

This file was deleted.

32 changes: 32 additions & 0 deletions Blocks/dist/buy-now/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "woo-vipps/buy-now",
"version": "2.0.0",
"title": "Vipps MobilePay Buy Now",
"attributes": {
"isInQuery": {
"type": "boolean",
"default": "false"
}
},
"keywords": [
"WooCommerce",
"woo-gutenberg-products-block"
],
"category": "woocommerce",
"parent": [
"woocommerce/product-template"
],
"usesContext": [
"query",
"queryId",
"postId"
],
"supports": {
"html": false
},
"textdomain": "woo-vipps",
"editorScript": "file:./index.js",
"render": "file:./render.php"
}
1 change: 1 addition & 0 deletions Blocks/dist/buy-now/index.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks'), 'version' => 'ff77120c8b85614bd344');
1 change: 1 addition & 0 deletions Blocks/dist/buy-now/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Blocks/dist/buy-now/render.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
$vipps = Vipps::instance();
$supports = false;
$pid = $block->context['postId'] ?? 0;
$product = $pid ? wc_get_product($pid) : 0;
if ($product && is_a($product, 'WC_Product')) {
$supports = $vipps->loop_single_product_is_express_checkout_purchasable($product);

}

// Only create button if the product has woo-vipps express checkout enabled. LP 29.11.2024
if ($supports) {
echo "<div class='wp-block-button wc-block-components-product-button wc-block-button-vipps'>" . $vipps->get_buy_now_button($product->get_id(), false) . "</div>";
}
2 changes: 1 addition & 1 deletion Blocks/dist/vipps-badge/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n'), 'version' => 'a24a031dce25d8203fb0');
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n'), 'version' => '0a1d868840342b2070f3');
2 changes: 1 addition & 1 deletion Blocks/dist/vipps-badge/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 49 additions & 35 deletions Blocks/woo-vipps-blocks.php
Original file line number Diff line number Diff line change
@@ -1,52 +1,66 @@
<?php

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

// Register blocks
add_action('init', function () {
register_block_type(__DIR__ . '/dist/vipps-badge');
// vipps-badge block. LP 29.11.2025
register_block_type(__DIR__ . '/dist/vipps-badge');

// Buy-now product block uses JS event introduced in woocommerce 9.4. LP 29.11.2024
if (version_compare(WC_VERSION, '9.4', '>=')) {
register_block_type(__DIR__ . '/dist/buy-now');

}
});

// Inject block config variables to vipps-badge editor script. LP 15.11.2024
// Inject block config variables to block editor assets
add_action('enqueue_block_editor_assets', function () {
$vipps = Vipps::instance();
$variants = $variants = [
// vipps-badge config
$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']];

// 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') {
// 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';
}
if ($store_language == 'da') {
}
if ($store_language == 'da') {
$store_language = 'dk';
}
if (!in_array($store_language, ['en', 'no', 'dk', 'fi'])) {
$store_language = 'en';
} // english default fallback

$block_config = [
'title' => sprintf(__('%1$s On-Site Messaging Badge', 'woo-vipps'), Vipps::CompanyName()),
'variants' => $variants,
'defaultVariant' => 'white',
'defaultLanguage' => $store_language,
'iconSrc' => plugins_url('../img/vipps-mobilepay-logo-only.png', __FILE__),
'brand' => strtolower($vipps->get_payment_method_name()),
'languages' => [
['label' => __('Default', 'woo-vipps'), 'value' => $store_language],
['label' => __('English', 'woo-vipps'), 'value' => 'en'],
['label' => __('Norwegian', 'woo-vipps'), 'value' => 'no'],
['label' => __('Finnish', 'woo-vipps'), 'value' => 'fi'],
['label' => __('Danish', 'woo-vipps'), 'value' => 'dk'],
],
];

wp_add_inline_script('woo-vipps-vipps-badge-editor-script',
'const injectedVippsBadgeBlockConfig = ' . json_encode($block_config),
'before');
});
}
if (!in_array($store_language, ['en', 'no', 'dk', 'fi'])) {
$store_language = 'en'; // english default fallback
}

$block_config = [
'title' => sprintf(__('%1$s On-Site Messaging Badge', 'woo-vipps'), Vipps::CompanyName()),
'variants' => $variants,
'defaultVariant' => 'white',
'defaultLanguage' => $store_language,
'iconSrc' => plugins_url('../img/vipps-mobilepay-logo-only.png', __FILE__),
'brand' => strtolower($vipps->get_payment_method_name()),
'languages' => [
['label' => __('Default', 'woo-vipps'), 'value' => $store_language],
['label' => __('English', 'woo-vipps'), 'value' => 'en'],
['label' => __('Norwegian', 'woo-vipps'), 'value' => 'no'],
['label' => __('Finnish', 'woo-vipps'), 'value' => 'fi'],
['label' => __('Danish', 'woo-vipps'), 'value' => 'dk'],
],
];
// vipps-badge config stop

// Inject block config to vipps-badge editor script. LP 15.11.2024
wp_add_inline_script('woo-vipps-vipps-badge-editor-script',
'const injectedVippsBadgeBlockConfig = ' . json_encode($block_config),
'before');

// Inject config from Vipps.class.php to buy-now editor script. LP 29.11.2024
if (version_compare(WC_VERSION, '9.4', '>=')) {
wp_add_inline_script('woo-vipps-buy-now-editor-script', 'const VippsConfig = ' . json_encode(Vipps::instance()->vippsJSConfig), 'before');
}
});
Loading

0 comments on commit cb7d990

Please sign in to comment.