Changeset 2826771
- Timestamp:
- 11/30/2022 10:51:20 PM (3 years ago)
- Location:
- doshii/trunk
- Files:
-
- 6 edited
-
README.txt (modified) (2 diffs)
-
doshii_function.php (modified) (1 diff)
-
include/woo-doshii-initialise.php (modified) (1 diff)
-
include/woo-doshii-product-sync.php (modified) (1 diff)
-
include/woo-order-api.php (modified) (12 diffs)
-
include/woo-order-status.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
doshii/trunk/README.txt
r2817460 r2826771 5 5 Requires at least: 4.7 6 6 Tested up to: 5.8.0 7 Stable tag: 2.5. 27 Stable tag: 2.5.3 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later … … 59 59 60 60 == Changelog == 61 62 = 2.5.3 = 63 64 Added support for discounted items through 3rd party plugins and custom product attributes 61 65 62 66 = 2.5.2 = -
doshii/trunk/doshii_function.php
r2817460 r2826771 7 7 Author URI: https://www.doshii.io 8 8 Contributors: 9 Version: 2.5. 29 Version: 2.5.3 10 10 */ 11 11 -
doshii/trunk/include/woo-doshii-initialise.php
r2817460 r2826771 40 40 'x-doshii-location-id' => $locationId.'', 41 41 'content-Type' => 'application/json', 42 'x-doshii-writeout' => 'WooCommerce 2.5. 2',42 'x-doshii-writeout' => 'WooCommerce 2.5.3', 43 43 ); 44 44 -
doshii/trunk/include/woo-doshii-product-sync.php
r2817460 r2826771 48 48 'x-doshii-location-id' => $locationId.'', 49 49 'content-Type' => 'application/json', 50 'x-doshii-writeout' => 'WooCommerce 2.5. 2',50 'x-doshii-writeout' => 'WooCommerce 2.5.3', 51 51 ) 52 52 )); -
doshii/trunk/include/woo-order-api.php
r2817460 r2826771 182 182 $product_id = $item->get_product_id(); 183 183 $variation_id = $item->get_variation_id(); 184 $product s= $item->get_product();185 $product_price = $product s->get_price();184 $product = $item->get_product(); 185 $product_price = $product->get_price(); 186 186 187 187 $name = $item->get_name(); … … 192 192 $productPrice = doshii_to_cents($product_price); 193 193 $centAmount = doshii_to_cents($subtotal); 194 195 $_product = wc_get_product( $product_id );196 194 197 195 $mappedProductId = get_post_meta($product_id, '_doshii_posId'); … … 279 277 $ppomPriceAddLabelPrefix = "<span class='ppom-option-label-price'>[+$"; 280 278 $ppomPriceRemoveLabelPrefix = "<span class='ppom-option-label-price'>[-$"; 279 $doshii_product_option_tbl = $wpdb->prefix . 'doshii_product_option'; 280 $doshii_product_variant_tbl = $wpdb->prefix . 'doshii_product_variant'; 281 281 $item_meta_data = $item->get_meta_data(); 282 282 if (!empty($item_meta_data)) { … … 284 284 // If the metadata is a product attribute then process item_meta_data as an option/variant 285 285 if (!empty($meta->key) && substr($meta->key, 0, 3) === 'pa_') { 286 $doshii_product_option_tbl = $wpdb->prefix . 'doshii_product_option';287 286 $metaOptionId = substr($meta->key, 3); // strip the 'pa_' from the start 288 287 … … 307 306 $variant_posId = ''; 308 307 if (!empty($option_posId)) { 309 $doshii_product_variant_tbl = $wpdb->prefix . 'doshii_product_variant';310 308 $metaVariantId = $meta->value; 311 309 $doshii_variant_sql = "SELECT * FROM $doshii_product_variant_tbl where doshii_product_id = '$mappedProductId' AND doshii_product_option_id='$option_posId' AND doshii_product_variant_id='$metaVariantId'"; … … 390 388 $metaOptionId = $optionKey; 391 389 392 $doshii_product_option_tbl = $wpdb->prefix . 'doshii_product_option';393 390 $doshii_option_sql = "SELECT * FROM $doshii_product_option_tbl where doshii_product_id = '$mappedProductId' AND doshii_product_option_id='$metaOptionId'"; 394 391 $doshii_option_record = $wpdb->get_row($doshii_option_sql); … … 408 405 409 406 $variants = []; 410 $doshii_product_variant_tbl = $wpdb->prefix . 'doshii_product_variant';411 407 412 408 // Convert to an array if it isn't already … … 529 525 else { 530 526 $metaDataKeyValues[$meta->key] = $meta->value; 527 528 // Handle custom attributes 529 $customAttributeLabel = wc_attribute_label($meta->key, $product); 530 if (!empty($customAttributeLabel) && $customAttributeLabel !== $meta->key) { 531 $customOptionId = $meta->key; 532 $customVariantId = $meta->value; 533 534 if (!empty($customVariantId)) { 535 $doshii_option_sql = "SELECT * FROM $doshii_product_option_tbl where doshii_product_id = '$mappedProductId' AND doshii_product_option_id='$customOptionId'"; 536 $doshii_option_record = $wpdb->get_row($doshii_option_sql); 537 538 $option_posId = $doshii_option_record->doshii_product_option_id; 539 $option_name = $doshii_option_record->doshii_product_option_name; 540 if (empty($option_name)) { 541 $doshii_custom_option_sql = "SELECT * FROM $doshii_product_option_tbl where doshii_product_id = '$mappedProductId' AND doshii_custom_id='$customOptionId'"; 542 $doshii_custom_option_record = $wpdb->get_row($doshii_custom_option_sql); 543 544 $option_posId = $doshii_custom_option_record->doshii_product_option_id; 545 $option_name = $doshii_custom_option_record->doshii_product_option_name; 546 if (empty($option_name)) { 547 $option_name = $customAttributeLabel; 548 } 549 } 550 551 $variant_name = $customVariantId; 552 $variant_posId = ''; 553 if (!empty($option_posId)) { 554 $doshii_variant_sql = "SELECT * FROM $doshii_product_variant_tbl where doshii_product_id = '$mappedProductId' AND doshii_product_option_id='$option_posId' AND doshii_product_variant_id='$customVariantId'"; 555 $doshii_variant_record = $wpdb->get_row($doshii_variant_sql); 556 557 $variant_posId = $doshii_variant_record->doshii_product_variant_id; 558 $variant_name = $doshii_variant_record->doshii_product_variant_name; 559 $variant_customPosId = $doshii_variant_record->doshii_custom_id; 560 if (empty($variant_name)) { 561 $doshii_custom_variant_sql = "SELECT * FROM $doshii_product_variant_tbl where doshii_product_id = '$mappedProductId' AND doshii_product_option_id='$option_posId' AND doshii_custom_id='$customVariantId'"; 562 $doshii_custom_variant_record = $wpdb->get_row($doshii_custom_variant_sql); 563 564 $variant_posId = $doshii_custom_variant_record->doshii_product_variant_id; 565 $variant_name = $doshii_custom_variant_record->doshii_product_variant_name; 566 $variant_customPosId = $doshii_custom_variant_record->doshii_custom_id; 567 if (empty($variant_name)) { 568 $variant_name = $customVariantId; 569 } 570 } 571 } 572 573 $variants = []; 574 if (empty($variant_posId)) { 575 array_push($variants, (object)[ 576 'name' => $variant_name, 577 'price' => 0 578 ]); 579 } else { 580 array_push($variants, (object)[ 581 'posId' => !empty($variant_customPosId) && strpos($variant_customPosId, "doshii:") === 0 ? $variant_customPosId : $variant_posId, 582 'name' => $variant_name, 583 'price' => 0 584 ]); 585 } 586 587 if (empty($option_posId)) { 588 array_push($doshiiOptions, (object)[ 589 'name' => $option_name, 590 'variants' => $variants 591 ]); 592 } else { 593 array_push($doshiiOptions, (object)[ 594 'posId' => $option_posId, 595 'name' => $option_name, 596 'variants' => $variants 597 ]); 598 } 599 } 600 } 531 601 } 532 602 } … … 535 605 $productType = 'single'; 536 606 } 537 }538 539 // If the product is a variable product then we need to extract the variation price540 if ($_product->is_type('variable')) {541 $variation = wc_get_product($variation_id);542 $variation = json_decode($variation);543 $productPrice = doshii_to_cents($variation->price);544 607 } 545 608 … … 547 610 'name' => $name, 548 611 'quantity' => $quantity, 549 'unitPrice' => $productPrice, 612 'unitPrice' => $productPrice, // default here, but re-calculated later 550 613 'options' => $doshiiOptions 551 614 ]; … … 571 634 $doshiiItem->totalAfterSurcounts = $centAmount; 572 635 $doshiiItem->surcounts = []; 636 637 // Safeguard on item price, in case there are 3rd party plugins altering the price 638 // Calculate backwards to get the unit price 639 $optionVariantPrice = 0; 640 foreach($doshiiOptions as $option) { 641 foreach($option->variants as $variant) { 642 $optionVariantPrice += $variant->price; 643 } 644 } 645 $doshiiItem->unitPrice = ($centAmount / $quantity) - $optionVariantPrice; 573 646 array_push($itemData, $doshiiItem); 574 647 } … … 635 708 'accept' => 'application/json', 636 709 'Accept-encoding' => 'gzip', 637 'x-doshii-writeout' => 'WooCommerce 2.5. 2',710 'x-doshii-writeout' => 'WooCommerce 2.5.3', 638 711 ), 639 712 'body' => json_encode($doshiiOrderPayload) -
doshii/trunk/include/woo-order-status.php
r2817460 r2826771 39 39 'x-doshii-location-id' => $doshii_options['location_id'].'', 40 40 'content-Type' => 'application/json', 41 'x-doshii-writeout' => 'WooCommerce 2.5. 2',41 'x-doshii-writeout' => 'WooCommerce 2.5.3', 42 42 ) 43 43 ));
Note: See TracChangeset
for help on using the changeset viewer.