Changeset 2108304
- Timestamp:
- 06/18/2019 06:13:00 PM (7 years ago)
- Location:
- cart66-cloud/trunk
- Files:
-
- 6 edited
-
cart66-cloud.php (modified) (1 diff)
-
includes/admin/cc-product-meta-box.php (modified) (5 diffs)
-
includes/class-cc-product.php (modified) (1 diff)
-
includes/cloud/class-cc-cloud-product.php (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
-
views/admin/html-product-meta-box.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cart66-cloud/trunk/cart66-cloud.php
r1868741 r2108304 4 4 Plugin URI: http://cart66.com 5 5 Description: Secure Ecommerce For WordPress. 6 Version: 2. 2.26 Version: 2.3.0 7 7 Author: Reality66 8 8 Author URI: http://www.reality66.com -
cart66-cloud/trunk/includes/admin/cc-product-meta-box.php
r1520079 r2108304 3 3 add_action( 'load-post.php', 'cc_product_meta_box_setup' ); 4 4 add_action( 'load-post-new.php', 'cc_product_meta_box_setup' ); 5 add_action( 'wp_ajax_cc_ajax_product_search', 'cc_ajax_product_search' );6 7 function cc_ajax_product_search( ) {8 CC_Log::write( 'AJAX product search: ' . print_r( $_REQUEST['search'], true ) );9 $products = CC_Cloud_Product::search( $_REQUEST['search'] );10 $options = array();11 12 /*13 Product info from search results: Array14 (15 [id] => 54d3e70dd2a57d1adc002eb116 [name] => Ooma HD2 Handset17 [sku] => hd218 [price] => 60.019 [on_sale] =>20 [sale_price] =>21 [currency] => $22 [expires_after] =>23 [formatted_price] => $60.0024 [formatted_sale_price] => $25 [digital] =>26 [type] => product27 [status] => available28 )29 */30 foreach ( $products as $p ) {31 CC_Log::write( 'Product info from search results: ' . print_r( $p, true ) );32 $options[] = array(33 'id' => json_encode( $p ),34 'text' => $p['name']35 );36 }37 38 echo json_encode( $options );39 die();40 }41 5 42 6 function cc_product_meta_box_setup() { … … 45 9 46 10 $url = cc_url(); 47 wp_enqueue_style( 'select2', $url .'resources/css/select2.css');48 wp_enqueue_s cript( 'select2', $url . 'resources/js/select2.min.js');49 11 //wp_enqueue_style( 'choices-base', 'https://cdn.jsdelivr.net/npm/choices.js/public/assets/styles/base.min.css'); 12 wp_enqueue_style( 'choices', 'https://cdn.jsdelivr.net/npm/choices.js/public/assets/styles/choices.min.css'); 13 wp_enqueue_script( 'choices', 'https://cdn.jsdelivr.net/npm/choices.js/public/assets/scripts/choices.min.js'); 50 14 } 51 15 … … 68 32 function cc_product_meta_box_render( $post, $box ) { 69 33 70 $ product_name = get_post_meta( $post->ID, '_cc_product_name', true );34 $selected_product_sku = get_post_meta( $post->ID, '_cc_product_sku', true ); 71 35 $layout = get_post_meta( $post->ID, '_cc_product_layout', true ); 72 73 if ( empty( $value ) ) { 74 $value = 'Select Product'; 75 } 36 $cloud_product = new CC_Cloud_Product(); 37 $cc_products = $cloud_product->get_products(); 76 38 77 39 $data = array( 78 40 'post' => $post, 79 41 'box' => $box, 80 'value' => $product_name, 81 'layout' => $layout 42 'selected_product_sku' => $selected_product_sku, 43 'layout' => $layout, 44 'cc_products' => $cc_products 82 45 ); 83 46 … … 126 89 $prefix = '_cc_product_'; 127 90 128 // Get the posted data and sanitize it for use as an HTML class.129 $product_info = ( isset( $_POST[ '_cc_product_json' ] ) ? sanitize_text_field( $_POST[ '_cc_product_json' ] ) : '');130 $product_info = stripslashes( $product_info);131 $product_info = json_decode( $product_info, true );91 if ( isset( $_POST[ '_cc_product_sku' ] ) && strlen( $_POST[ '_cc_product_sku' ] ) > 0 ) { 92 $cc_product = CC_Cloud_Product::find_by_sku($_POST[ '_cc_product_sku' ]); 93 CC_Log::write( print_r($cc_product, true) ); 94 } 132 95 133 if ( is_array( $ product_info) ) {96 if ( is_array( $cc_product ) ) { 134 97 135 98 // Get the meta value of the custom field key. … … 138 101 if ( '' == $old_value ) { 139 102 // If a new meta value was added and there was no previous value, add it. 140 add_post_meta( $post_id, $json_key, $ product_info, true );141 foreach( $ product_infoas $key => $value ) {103 add_post_meta( $post_id, $json_key, $cc_product, true ); 104 foreach( $cc_product as $key => $value ) { 142 105 add_post_meta( $post_id, $prefix . $key, $value, true ); 143 106 } 144 } elseif ( $ product_info!= $old_value ) {107 } elseif ( $cc_product != $old_value ) { 145 108 // If the new meta value does not match the old value, update it. 146 update_post_meta( $post_id, $json_key, $ product_info);147 foreach( $ product_infoas $key => $value ) {109 update_post_meta( $post_id, $json_key, $cc_product ); 110 foreach( $cc_product as $key => $value ) { 148 111 update_post_meta( $post_id, $prefix . $key, $value ); 149 112 } 150 } elseif ( '' == $ product_info&& $old_value ) {113 } elseif ( '' == $cc_product && $old_value ) { 151 114 // TODO: $product_info will never be empty here because in order to get here it has to be an array 152 115 // If there is no new meta value but an old value exists, delete it. -
cart66-cloud/trunk/includes/class-cc-product.php
r1868741 r2108304 115 115 $post = array_shift( $posts ); 116 116 if ( is_object( $post ) && $post->ID > 0 ) { 117 $ results = CC_Cloud_Product::search( $sku );117 $cc_product = CC_Cloud_Product::find_by_sku( $sku ); 118 118 // CC_Log::write( 'Updating product info for post id: ' . $post->ID . " :: " . print_r( $results, true ) ); 119 if( is_array( $results ) && count( $results ) ) { 120 $product_info = array_shift( $results ); 121 update_post_meta( $post->ID, $this->json_key, $product_info ); 122 foreach( $product_info as $key => $value ) { 119 if( is_array( $cc_product ) ) { 120 update_post_meta( $post->ID, $this->json_key, $cc_product ); 121 foreach( $cc_product as $key => $value ) { 123 122 update_post_meta( $post->ID, $this->prefix . $key, $value ); 124 123 } -
cart66-cloud/trunk/includes/cloud/class-cc-cloud-product.php
r1520079 r2108304 141 141 } 142 142 143 public static function find_by_sku( $sku ) { 144 self::init(); 145 146 CC_Log::write( "CC_Cloud_Product query param: " . print_r( $sku, true ) ); 147 $url = self::$cloud->api . 'products/sku/' . urlencode( $sku ); 148 149 CC_Log::write( "Search the cloud for products with this URL: $url" ); 150 151 $headers = self::$cloud->basic_auth_header( array( 'Accept' => 'application/json' ) ); 152 153 if ( $headers ) { 154 $response = wp_remote_get( $url, $headers ); 155 156 if( self::$cloud->response_ok( $response ) ) { 157 $product = json_decode( $response['body'], true ); 158 } else { 159 CC_Log::write( "Product search failed: $url :: " . print_r( $response, true ) ); 160 throw new CC_Exception_API( "Failed to retrieve products from Cart66 Cloud" ); 161 } 162 } 163 164 return $product; 165 } 166 167 143 168 } -
cart66-cloud/trunk/readme.txt
r1868741 r2108304 5 5 Requires at least: 4.0 6 6 Requires PHP: 5.4 7 Tested up to: 4.98 Stable tag: 2. 2.27 Tested up to: 5.2.1 8 Stable tag: 2.3.0 9 9 License: GPLv3 10 10 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 91 91 = Minimum Requirements = 92 92 93 * WordPress 3.2or greater93 * WordPress 4.0 or greater 94 94 * PHP version 5.4 or greater 95 95 * MySQL version 5.0 or greater … … 138 138 139 139 == Changelog == 140 141 = 2.3.0 = 142 - Fix: Issue with product catalog showing incorrect prices for products 143 - Fix: Metabox for selecting the product for a Product post type didn't always 144 save correctly 145 - Update: Other minor stability improvements and library updates 140 146 141 147 = 2.2.2 = -
cart66-cloud/trunk/views/admin/html-product-meta-box.php
r1520079 r2108304 9 9 ?> 10 10 11 <script langage="text/javascript"> 12 jQuery(document).ready(function($) { 11 <style type="text/css"> 12 .choices .choices__inner { 13 min-height: auto; 14 padding-right: 0; 15 width: 90%; 16 } 13 17 14 $('#_cc_product_json').select2({ 15 width: '100%', 16 minimumInputLength: 2, 17 allowClear: true, 18 ajax: { 19 url: ajaxurl, 20 dataType: 'json', 21 data: function (term, page) { 22 return { 23 action: 'cc_ajax_product_search', 24 search: term 25 }; 26 }, 27 results: function (data, page) { 28 return { results: data }; 29 } 30 } 31 }); 18 .choices .choices__list--single { 19 width: 90%; 20 } 32 21 22 .choices .choices__item--selectable { 23 width: 90%; 24 } 33 25 34 }); 35 </script> 26 .choices[data-type*=select-one]:after { 27 right: 35px; 28 } 29 30 .choices .choices__list--dropdown { 31 width: 93%; 32 } 33 </style> 36 34 37 35 <div class="cc_meta_box_option"> 38 <input type="hidden" name="_cc_product_json" id="_cc_product_json" data-placeholder="<?php echo $value; ?>" /> 36 <select name="_cc_product_sku" id="_cc_product_sku" class="choices"> 37 <option placeholder value="">Choose Product</option> 38 <?php foreach ($cc_products as $cc_product): ?> 39 <?php if ($cc_product["sku"] == $selected_product_sku): ?> 40 <option value="<?php echo $cc_product["sku"] ?>" selected> 41 <?php echo $cc_product["name"] ?> 42 </option> 43 <?php else: ?> 44 <option value="<?php echo $cc_product["sku"] ?>"> 45 <?php echo $cc_product["name"] ?> 46 </option> 47 <?php endif ?> 48 <?php endforeach ?> 49 </select> 39 50 </div> 40 51 … … 49 60 </select> 50 61 </div> 62 63 <script> 64 $(document).ready(function() { 65 var choices = new Choices($(".choices")[0], { 66 }); 67 }); 68 </script>
Note: See TracChangeset
for help on using the changeset viewer.