-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
2.6.3
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "mycred-woocommerce/mycred-woo-cart-block", | ||
"version": "1.0.0", | ||
"title": "myCred WooCommerce", | ||
"category": "woocommerce", | ||
"attributes": { | ||
"lock": { | ||
"type": "object", | ||
"default": { | ||
"remove": true, | ||
"move": true | ||
} | ||
} | ||
}, | ||
"textdomain": "mycred-woocommerce", | ||
"editorScript": "file:./build/index.js" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wc-settings', 'wp-i18n'), 'version' => 'edcd41835330a175b895'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wp-i18n'), 'version' => 'a15b43583f591fe0e1d4'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "mycred-woocommerce/mycred-woo-checkout-block", | ||
"version": "1.0.0", | ||
"title": "myCred WooCommerce", | ||
"category": "woocommerce", | ||
"parent": [ | ||
"woocommerce/checkout-totals-block" | ||
], | ||
"attributes": { | ||
"lock": { | ||
"type": "object", | ||
"default": { | ||
"remove": true, | ||
"move": true | ||
} | ||
} | ||
}, | ||
"textdomain": "mycred-woocommerce", | ||
"editorScript": "file:./build/index.js" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wc-settings', 'wp-i18n'), 'version' => 'b269d62462cc4037fd8c'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('wp-blocks'), 'version' => '1c1705295c8feec35d0e'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "mycred-woocommerce/mycred-woo-payment-gateway", | ||
"version": "1.0.0", | ||
"title": "myCred WooCommerce", | ||
"category": "woocommerce", | ||
"parent": [ | ||
"woocommerce/checkout-payment-block" | ||
], | ||
"attributes": { | ||
"lock": { | ||
"type": "object", | ||
"default": { | ||
"remove": false, | ||
"move": false | ||
} | ||
} | ||
}, | ||
"textdomain": "mycred-woocommerce", | ||
"editorScript": "file:./build/payment/index.js" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wp-blocks', 'wp-i18n'), 'version' => 'd83b52bee15e86c16da1'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-html-entities', 'wp-i18n'), 'version' => '6e9534c4ae40018806cc'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* myCred_Woo_Blocks_Compatibility class | ||
*/ | ||
|
||
// Exit if accessed directly. | ||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; | ||
} | ||
|
||
/** | ||
* WooCommerce Blocks Compatibility. | ||
*/ | ||
class myCred_Woo_Blocks_Compatibility { | ||
|
||
/** | ||
* Initialize. | ||
*/ | ||
public static function init() { | ||
|
||
if ( ! did_action( 'woocommerce_blocks_loaded' ) ) { | ||
return; | ||
} | ||
|
||
require_once myCRED_GATE_BLOCKS_DIR . 'mycred-woo-block-store-api.php'; | ||
require_once myCRED_GATE_BLOCKS_DIR . 'mycred-woo-checkout-block-integration.php'; | ||
require_once myCRED_GATE_BLOCKS_DIR . 'mycred-woo-cart-block-integration.php'; | ||
|
||
myCred_Woo_Extend_Store_Endpoint::init(); | ||
|
||
/** | ||
* Registers myCred WooCommerce Cart Block Integration. | ||
*/ | ||
add_action( | ||
'woocommerce_blocks_cart_block_registration', | ||
function( $integration_registry ) { | ||
$integration_registry->register( new myCred_Woo_Cart_Blocks_Integration() ); | ||
} | ||
); | ||
|
||
/** | ||
* Registers myCred WooCommerce Checkout Block Integration. | ||
*/ | ||
add_action( | ||
'woocommerce_blocks_checkout_block_registration', | ||
function( $integration_registry ) { | ||
$integration_registry->register( new myCred_Woo_Checkout_Blocks_Integration() ); | ||
} | ||
); | ||
|
||
/** | ||
* Registers myCred WooCommerce Payment Method. | ||
*/ | ||
if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) { | ||
require_once myCRED_GATE_BLOCKS_DIR . 'mycred-woo-payment-method-integration.php'; | ||
add_action( | ||
'woocommerce_blocks_payment_method_type_registration', | ||
static function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) { | ||
$payment_method_registry->register( new MyCred_Woo_Payment_Method() ); | ||
} | ||
); | ||
} | ||
} | ||
} | ||
|
||
myCred_Woo_Blocks_Compatibility::init(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<?php | ||
/** | ||
* myCred_Woo_Extend_Store_API class | ||
*/ | ||
|
||
// Exit if accessed directly. | ||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; | ||
} | ||
|
||
use Automattic\WooCommerce\StoreApi\StoreApi; | ||
use Automattic\WooCommerce\StoreApi\Schemas\V1\CartSchema; | ||
|
||
class myCred_Woo_Extend_Store_Endpoint { | ||
|
||
/** | ||
* Plugin Identifier, unique to each plugin. | ||
* | ||
* @var string | ||
*/ | ||
const IDENTIFIER = 'mycredwoo'; | ||
|
||
/** | ||
* Initialize. | ||
*/ | ||
public static function init() { | ||
if ( ! function_exists( 'woocommerce_store_api_register_endpoint_data' ) ) { | ||
return; | ||
} | ||
|
||
woocommerce_store_api_register_endpoint_data( | ||
array( | ||
'endpoint' => CartSchema::IDENTIFIER, | ||
'namespace' => self::IDENTIFIER, | ||
'data_callback' => array( 'myCred_Woo_Extend_Store_Endpoint', 'extend_checkout_block_data' ), | ||
'schema_callback' => array( 'myCred_Woo_Extend_Store_Endpoint', 'extend_checkout_block_schema' ), | ||
'schema_type' => ARRAY_A, | ||
) | ||
); | ||
|
||
} | ||
|
||
/** | ||
* Register myCred WooCommerce data into cart/checkout endpoint. | ||
* | ||
* @return array $item_data Registered data or empty array if condition is not satisfied. | ||
*/ | ||
public static function extend_checkout_block_data() { | ||
|
||
if ( ! is_user_logged_in() ) { | ||
return array(); | ||
} | ||
|
||
// Only available for logged in non-excluded users | ||
global $woocommerce; | ||
|
||
$cart_total = ''; | ||
if ( isset( WC()->session->cart_totals ) && WC()->session->cart_totals ) { | ||
$cart_total = WC()->session->cart_totals['total']; | ||
} | ||
|
||
$available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways(); | ||
if ( ! isset( $available_gateways['mycred'] ) ) { | ||
return array(); | ||
} | ||
|
||
$point_type = $available_gateways['mycred']->get_option( 'point_type' ); | ||
|
||
if ( $point_type === NULL ) { | ||
$point_type = MYCRED_DEFAULT_TYPE_KEY; | ||
} | ||
|
||
$mycred = mycred( $point_type ); | ||
$user_id = get_current_user_id(); | ||
|
||
// Nothing to do if we are excluded | ||
if ( $mycred->exclude_user( $user_id ) ) { | ||
return array(); | ||
} | ||
|
||
$show_total = $available_gateways['mycred']->get_option( 'show_total' ); | ||
$balance = $mycred->get_users_balance( $user_id, $point_type ); | ||
$balance_label = $available_gateways['mycred']->get_option( 'balance_format' ); | ||
$cost = ''; | ||
$order_total_in_points = ''; | ||
|
||
$currency = get_woocommerce_currency(); | ||
if ( ! mycred_point_type_exists( $currency ) && $currency != 'MYC' ) { | ||
if ( $cart_total ) { | ||
// Apply Exchange Rate | ||
$cost = $mycred->number( ( $cart_total / $available_gateways['mycred']->get_option( 'exchange_rate' ) ) ); | ||
} | ||
$order_total_in_points = $mycred->template_tags_general( $available_gateways['mycred']->get_option( 'total_label' ) ); | ||
} | ||
|
||
if ( $balance < $cost ) { | ||
$enabled = 'no'; | ||
} else { | ||
$enabled = 'yes'; | ||
} | ||
|
||
$item_data = array( | ||
'mycred_woo_total' => $mycred->format_creds( $cost ), | ||
'mycred_woo_total_label' => $order_total_in_points, | ||
'mycred_woo_balance' => $mycred->format_creds( $balance ), | ||
'mycred_woo_balance_label' => $balance_label, | ||
'payment_gateway' => $enabled, | ||
|
||
); | ||
|
||
return $item_data; | ||
} | ||
|
||
/** | ||
* Register myCred WooCommerce schema into cart/checkout endpoint. | ||
* | ||
* @return array Registered schema. | ||
*/ | ||
public static function extend_checkout_block_schema() { | ||
return array( | ||
'mycred_woo_total' => array( | ||
'description' => __( 'myCred WooCommerce order total.', 'mycred-woocommerce' ), | ||
'type' => array( 'integer', 'null' ), | ||
'context' => array( 'view', 'edit' ), | ||
'readonly' => true, | ||
), | ||
'mycred_woo_total_label' => array( | ||
'description' => __( 'The label of myCred WooCommece total field', 'mycred-woocommerce' ), | ||
'type' => array( 'string', 'null' ), | ||
'context' => array( 'view', 'edit' ), | ||
'readonly' => true, | ||
), | ||
'mycred_woo_balance' => array( | ||
'description' => __( 'The balance of myCred points', 'mycred-woocommerce' ), | ||
'type' => array( 'integer', 'null' ), | ||
'context' => array( 'view', 'edit' ), | ||
'readonly' => true, | ||
), | ||
'mycred_woo_balance_label' => array( | ||
'description' => __( 'The label of myCred points balance field', 'mycred-woocommerce' ), | ||
'type' => array( 'string', 'null' ), | ||
'context' => array( 'view', 'edit' ), | ||
'readonly' => true, | ||
), | ||
); | ||
} | ||
} |