Changeset 2504530
- Timestamp:
- 03/27/2021 06:40:42 PM (5 years ago)
- Location:
- voucherify/trunk
- Files:
-
- 7 edited
-
readme.txt (modified) (2 diffs)
-
src/class-voucherify-order-placing-session.php (modified) (6 diffs)
-
src/class-voucherify-save-order-listener.php (modified) (3 diffs)
-
src/class-voucherify-validation-service.php (modified) (1 diff)
-
src/class-voucherify.php (modified) (1 diff)
-
src/functions.php (modified) (4 diffs)
-
voucherify.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
voucherify/trunk/readme.txt
r2502135 r2504530 7 7 WC tested up to: 4.3.1 8 8 WC requires at least: 3.0.0 9 Stable tag: 2.1. 19 Stable tag: 2.1.2 10 10 11 11 Integrates Voucherify API with woocommerce … … 50 50 == Changelog == 51 51 52 = 2.1.2 - 2021-03-27 = 53 * Fix: Supporting vouchers via Woocommerce REST API 54 52 55 = 2.1.1 - 2021-03-23 = 53 56 * Added Spanish Language Pack -
voucherify/trunk/src/class-voucherify-order-placing-session.php
r2491101 r2504530 8 8 class Voucherify_Order_Placing_Session { 9 9 10 private $fake_session_for_rest_api = [ 11 'voucherify_valid_vouchers' => [], 12 'voucherify_removed_coupons' => [] 13 ]; 10 14 11 15 /** … … 16 20 */ 17 21 public function set_validation_response( $code, $response ) { 22 if ( vcrf_is_rest_request() ) { 23 $this->fake_session_for_rest_api['voucherify_valid_vouchers'][ $code ] = $response; 24 25 return; 26 } 27 18 28 $validations = empty( WC()->session ) ? [] : WC()->session->get( 'voucherify_valid_vouchers' ); 19 29 if ( ! is_array( $validations ) ) { … … 46 56 */ 47 57 public function get_all_validation_responses() { 58 if ( vcrf_is_rest_request() ) { 59 return $this->fake_session_for_rest_api['voucherify_valid_vouchers']; 60 } 48 61 if ( ! empty( WC()->session ) && isset( WC()->session->voucherify_valid_vouchers ) ) { 49 62 return WC()->session->voucherify_valid_vouchers; … … 59 72 */ 60 73 public function add_removed_coupon( $code ) { 74 if ( vcrf_is_rest_request() ) { 75 $this->fake_session_for_rest_api['voucherify_removed_coupons'][] = $code; 76 77 return; 78 } 61 79 $removed_coupons = empty( WC()->session ) ? [] : WC()->session->get( 'voucherify_removed_coupons' ); 62 80 if ( ! is_array( $removed_coupons ) ) { … … 87 105 */ 88 106 public function get_removed_coupons() { 107 if ( vcrf_is_rest_request() ) { 108 return $this->fake_session_for_rest_api['voucherify_removed_coupons']; 109 } 89 110 $removed_coupons = empty( WC()->session ) ? [] : WC()->session->get( 'voucherify_removed_coupons' ); 90 111 … … 119 140 */ 120 141 public function clear() { 142 if ( vcrf_is_rest_request() ) { 143 $this->fake_session_for_rest_api['voucherify_removed_coupons'] = []; 144 $this->fake_session_for_rest_api['voucherify_valid_vouchers'] = []; 145 146 return; 147 } 121 148 if ( ! empty( WC()->session ) ) { 122 149 unset( WC()->session->voucherify_removed_coupons ); -
voucherify/trunk/src/class-voucherify-save-order-listener.php
r2491101 r2504530 55 55 */ 56 56 public function on_before_order_save( WC_Order $order ) { 57 if ( vcrf_is_rest_request() ) { 58 global $vcrf_current_order; 59 $vcrf_current_order = $order; 60 } 57 61 if ( ! in_array( $order->get_status(), [ 'processing', 'completed' ] ) ) { 58 62 return; 59 63 } 60 64 61 if ( is_admin() && ( ! defined( 'VCRF_FETCH_PROMOTIONS' ) || ! VCRF_FETCH_PROMOTIONS ) ) {65 if ( vcrf_is_rest_request() || is_admin() && ( ! defined( 'VCRF_FETCH_PROMOTIONS' ) || ! VCRF_FETCH_PROMOTIONS ) ) { 62 66 $this->maybe_remove_free_shipping_coupon(); 63 67 $this->handle_order_save_by_admin( $order ); … … 113 117 114 118 private function get_shipping_methods() { 115 if ( ! is_admin() ) {119 if ( ! vcrf_is_rest_request() && ! is_admin() ) { 116 120 return WC()->session->get( 'chosen_shipping_methods' ); 117 121 } … … 128 132 129 133 private function get_applied_coupons() { 130 if ( ! is_admin() ) {134 if ( ! vcrf_is_rest_request() && ! is_admin() ) { 131 135 return WC()->cart->get_applied_coupons(); 132 136 } -
voucherify/trunk/src/class-voucherify-validation-service.php
r2491101 r2504530 409 409 private function save_session_key( $code, $response ) { 410 410 //add coupon by customer 411 if ( ! is_admin() ) {411 if ( ! vcrf_is_rest_request() && ! is_admin() ) { 412 412 $this->order_placing_session->set_validation_response( $code, $response ); 413 413 -
voucherify/trunk/src/class-voucherify.php
r2491101 r2504530 102 102 103 103 if ( is_voucherify_enabled() ) { 104 104 105 /** 105 106 * By default WC coupon's code is case insensitive. -
voucherify/trunk/src/functions.php
r2491101 r2504530 68 68 function vcrf_get_order_data( WC_Order $order = null ) { 69 69 $is_pending = ! empty( $order ) && $order->get_status() === 'pending'; 70 if ( ! $is_pending && ( ! is_admin() || ( defined( 'VCRF_FETCH_PROMOTIONS' ) && VCRF_FETCH_PROMOTIONS ) ) ) { 70 if ( ! vcrf_is_rest_request() && ! $is_pending 71 && ( ! is_admin() || ( defined( 'VCRF_FETCH_PROMOTIONS' ) && VCRF_FETCH_PROMOTIONS ) ) ) { 71 72 $cart_decorator = new Voucherify_Cart_Decorator( WC()->cart ); 72 73 … … 148 149 return wc_get_order( $_POST['order_id'] ); 149 150 } 151 if ( vcrf_is_rest_request() ) { 152 global $vcrf_current_order; 153 154 return $vcrf_current_order; 155 } 150 156 151 157 return null; … … 161 167 */ 162 168 function vcrf_get_customer_data() { 163 if ( ! is_admin() || ( defined( 'VCRF_FETCH_PROMOTIONS' ) && VCRF_FETCH_PROMOTIONS) ) {169 if ( ! vcrf_is_rest_request() && ( ! is_admin() || ( defined( 'VCRF_FETCH_PROMOTIONS' ) && VCRF_FETCH_PROMOTIONS ) ) ) { 164 170 $customer_decorator = new Voucherify_Customer_Decorator( WC()->customer ); 165 171 … … 189 195 } 190 196 } 197 198 if ( ! function_exists( 'vcrf_is_rest_request' ) ) { 199 /** 200 * Checks if the request is made by the REST API 201 * 202 * @return bool 203 */ 204 function vcrf_is_rest_request() { 205 return defined( 'REST_REQUEST' ); 206 } 207 } -
voucherify/trunk/voucherify.php
r2502135 r2504530 8 8 * Plugin URI: https://wordpress.org/plugins/voucherify/ 9 9 * Description: Integrates Voucherify API with woocommerce replacing core coupons functionality 10 * Version: 2.1. 110 * Version: 2.1.2 11 11 * Author: rspective 12 12 * Author URI: https://www.rspective.com/
Note: See TracChangeset
for help on using the changeset viewer.