Changeset 1868048
- Timestamp:
- 05/03/2018 11:00:52 AM (8 years ago)
- Location:
- chatx-ai/trunk
- Files:
-
- 3 edited
-
chatx-ai.php (modified) (1 diff)
-
includes/class-chatx-ai-rest-api.php (modified) (4 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
chatx-ai/trunk/chatx-ai.php
r1863592 r1868048 4 4 * Plugin URI: https://chatx.ai 5 5 * Description: Advanced Instant Search 6 * Version: 0. 1.96 * Version: 0.2.0 7 7 * Author: chatx.ai 8 8 * Author URI: https://chatx.ai -
chatx-ai/trunk/includes/class-chatx-ai-rest-api.php
r1863159 r1868048 179 179 } 180 180 181 static function getAttributeValuesArray($isTax, $values){ 182 if($isTax){ 183 return explode(',', str_replace(', ', ',', $values)); 184 } 185 else{ 186 return explode('|', str_replace(' | ', '|', str_replace('| ', '|', str_replace(' |', '|', $values)))); 187 } 188 } 189 190 static function getProductAttributes($wooProduct){ 191 192 $attributes = []; 193 $attributeId = 0; 194 195 foreach ( $wooProduct->get_attributes() as $attributeKey => $attribute ) { 196 197 $attributeKeyFormatted = str_replace('pa_', '', $attributeKey); 198 199 if(is_array($attribute)){ 200 201 $attrTerms = get_terms($attribute['name']); 202 203 $attributeOptions = []; 204 205 $attributeTerms = is_array($attrTerms) ? $attrTerms : []; 206 foreach ($attributeTerms as $attributeTerm) { 207 $attributeOptions[] = $attributeTerm->slug; 208 } 209 210 $attributes[] = [ 211 'id' => $wooProduct->get_id() . '-' . $attributeId, 212 'name' => ucfirst(str_replace('pa_', '', $attribute['name'])), 213 'key' => $attributeKeyFormatted, 214 'options' => $attributeOptions, 215 'is_taxonomy' => $attribute['is_taxonomy'], 216 'position' => $attribute['position'], 217 'visible' => $attribute['is_visible'], 218 'variation' => $attribute['is_variation'], 219 'values' => Chatx_Ai_Rest_API::getAttributeValuesArray($attribute['is_taxonomy'], $wooProduct->get_attribute($attribute['name'])) 220 ]; 221 222 } 223 else{ 224 225 $attributes[] = [ 226 'id' => $wooProduct->get_id() . '-' . $attribute->get_id(), 227 'name' => ucfirst(str_replace('pa_', '', $attribute->get_name())), 228 'key' => $attributeKeyFormatted, 229 'options' => $attribute->get_slugs( ), 230 'is_taxonomy' => $attribute->is_taxonomy(), 231 'position' => $attribute->get_position(), 232 'visible' => $attribute->get_visible(), 233 'variation' => $attribute->get_variation(), 234 'values' => Chatx_Ai_Rest_API::getAttributeValuesArray($attribute['is_taxonomy'], $wooProduct->get_attribute($attribute->get_name())) 235 ]; 236 237 } 238 239 $attributeId++; 240 } 241 242 return $attributes; 243 } 244 181 245 static function getProductInFormat($product){ 182 246 … … 197 261 198 262 $variations = []; 199 $attributes = [];200 263 201 264 if($wooProduct->is_type( 'variable' )){ … … 215 278 'inventory_quantity' => $variation['is_in_stock'] ? 1 : 0, 216 279 'vendor' => null, 217 'title' => null 280 'title' => null, 281 'options' => [] 218 282 ]; 219 283 220 $optionIndex = 0;221 284 foreach ($variation['attributes'] as $attributeKey => $attribute) { 222 $optionIndex++; 223 $variationFormated['option_' . $optionIndex] = $attribute; 285 286 $attributeKeyFormatted = str_replace('attribute_', '', str_replace('attribute_pa_', '', $attributeKey)); 287 $variationFormated['options'][$attributeKeyFormatted] = $attribute; 224 288 } 225 289 226 290 $variations[] = $variationFormated; 227 }228 229 $attributeId = 0;230 foreach ( $wooProduct->get_attributes() as $attributeKey => $attribute ) {231 232 if(is_array($attribute)){233 234 $attrTerms = get_terms($attribute['name']);235 236 $attributeOptions = [];237 238 $attributeTerms = is_array($attrTerms) ? $attrTerms : [];239 foreach ($attributeTerms as $attributeTerm) {240 $attributeOptions[] = $attributeTerm->slug;241 }242 243 $attributes[] = [244 'id' => $product->ID . '-' . $attributeId,245 'name' => ucfirst(str_replace('pa_', '', $attribute['name'])),246 'options' => $attributeOptions,247 'is_taxonomy' => $attribute['is_taxonomy'],248 'position' => $attribute['position'],249 'visible' => $attribute['is_visible'],250 'variation' => $attribute['is_variation']251 ];252 253 }254 else{255 256 $attributes[] = [257 'id' => $product->ID . '-' . $attribute->get_id(),258 'name' => ucfirst(str_replace('pa_', '', $attribute->get_name())),259 'options' => $attribute->get_slugs( ),260 'is_taxonomy' => $attribute->is_taxonomy(),261 'position' => $attribute->get_position(),262 'visible' => $attribute->get_visible(),263 'variation' => $attribute->get_variation()264 ];265 266 }267 268 $attributeId++;269 291 } 270 292 } … … 293 315 'sku' => $wooProduct->get_sku(), 294 316 'variations' => $variations, 295 'attributes' => $attributes,317 'attributes' => Chatx_Ai_Rest_API::getProductAttributes($wooProduct), 296 318 'price' => $wooProduct->get_price(), 297 319 'compare_at_price' => $wooProduct->get_regular_price(), -
chatx-ai/trunk/readme.txt
r1863592 r1868048 3 3 Tags: instant search, advanced search, woocommerce, image search, voice search 4 4 Tested up to: 4.9.5 5 Stable tag: 0. 1.95 Stable tag: 0.2.0 6 6 Requires at least: 4.0 7 7 … … 110 110 111 111 == Installation == 112 Install like any other plugin, directly from your plugins page. After you activate the plugin, you will be prompted to “Connect with ChatX.ai”. This will bring the chatbot alive and it’s a very important step for everything to work well.112 Install like any other plugin, directly from your plugins page. 113 113 114 114 == How to uninstall ChatX.ai ==
Note: See TracChangeset
for help on using the changeset viewer.