Plugin Directory

Changeset 2826771


Ignore:
Timestamp:
11/30/2022 10:51:20 PM (3 years ago)
Author:
doshii
Message:

Submitting changes for release 2.5.3

Location:
doshii/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • doshii/trunk/README.txt

    r2817460 r2826771  
    55Requires at least: 4.7
    66Tested up to: 5.8.0
    7 Stable tag: 2.5.2
     7Stable tag: 2.5.3
    88Requires PHP: 7.0
    99License: GPLv2 or later
     
    5959
    6060== Changelog ==
     61
     62= 2.5.3 =
     63
     64Added support for discounted items through 3rd party plugins and custom product attributes
    6165
    6266= 2.5.2 =
  • doshii/trunk/doshii_function.php

    r2817460 r2826771  
    77Author URI: https://www.doshii.io
    88Contributors:
    9 Version: 2.5.2
     9Version: 2.5.3
    1010*/
    1111
  • doshii/trunk/include/woo-doshii-initialise.php

    r2817460 r2826771  
    4040       'x-doshii-location-id' => $locationId.'',
    4141       'content-Type' => 'application/json',
    42        'x-doshii-writeout' => 'WooCommerce 2.5.2',
     42       'x-doshii-writeout' => 'WooCommerce 2.5.3',
    4343    );
    4444
  • doshii/trunk/include/woo-doshii-product-sync.php

    r2817460 r2826771  
    4848            'x-doshii-location-id' => $locationId.'',
    4949            'content-Type' => 'application/json',
    50             'x-doshii-writeout' => 'WooCommerce 2.5.2',
     50            'x-doshii-writeout' => 'WooCommerce 2.5.3',
    5151        )
    5252    ));
  • doshii/trunk/include/woo-order-api.php

    r2817460 r2826771  
    182182        $product_id = $item->get_product_id();
    183183        $variation_id = $item->get_variation_id();
    184         $products = $item->get_product();
    185         $product_price = $products->get_price();
     184        $product = $item->get_product();
     185        $product_price = $product->get_price();
    186186
    187187        $name = $item->get_name();
     
    192192        $productPrice = doshii_to_cents($product_price);
    193193        $centAmount = doshii_to_cents($subtotal);
    194 
    195         $_product = wc_get_product( $product_id );
    196194
    197195        $mappedProductId = get_post_meta($product_id, '_doshii_posId');
     
    279277        $ppomPriceAddLabelPrefix = "<span class='ppom-option-label-price'>[+&#36;";
    280278        $ppomPriceRemoveLabelPrefix = "<span class='ppom-option-label-price'>[-&#36;";
     279        $doshii_product_option_tbl  = $wpdb->prefix . 'doshii_product_option';
     280        $doshii_product_variant_tbl  = $wpdb->prefix . 'doshii_product_variant';
    281281        $item_meta_data = $item->get_meta_data();
    282282        if (!empty($item_meta_data)) {
     
    284284                // If the metadata is a product attribute then process item_meta_data as an option/variant
    285285                if (!empty($meta->key) && substr($meta->key, 0, 3) === 'pa_') {
    286                     $doshii_product_option_tbl  = $wpdb->prefix . 'doshii_product_option';
    287286                    $metaOptionId = substr($meta->key, 3); // strip the 'pa_' from the start
    288287
     
    307306                        $variant_posId = '';
    308307                        if (!empty($option_posId)) {
    309                             $doshii_product_variant_tbl  = $wpdb->prefix . 'doshii_product_variant';
    310308                            $metaVariantId = $meta->value;
    311309                            $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'";
     
    390388                            $metaOptionId = $optionKey;
    391389
    392                             $doshii_product_option_tbl  = $wpdb->prefix . 'doshii_product_option';
    393390                            $doshii_option_sql = "SELECT * FROM $doshii_product_option_tbl where doshii_product_id = '$mappedProductId' AND doshii_product_option_id='$metaOptionId'";
    394391                            $doshii_option_record = $wpdb->get_row($doshii_option_sql);
     
    408405
    409406                            $variants = [];
    410                             $doshii_product_variant_tbl  = $wpdb->prefix . 'doshii_product_variant';
    411407
    412408                            // Convert to an array if it isn't already
     
    529525                else {
    530526                    $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                    }
    531601                }
    532602            }
     
    535605                $productType = 'single';
    536606            }
    537         }
    538 
    539         // If the product is a variable product then we need to extract the variation price
    540         if ($_product->is_type('variable')) {
    541             $variation = wc_get_product($variation_id);
    542             $variation = json_decode($variation);
    543             $productPrice =  doshii_to_cents($variation->price);
    544607        }
    545608
     
    547610            'name' => $name,
    548611            'quantity' => $quantity,
    549             'unitPrice' => $productPrice,
     612            'unitPrice' => $productPrice, // default here, but re-calculated later
    550613            'options' => $doshiiOptions
    551614        ];
     
    571634            $doshiiItem->totalAfterSurcounts = $centAmount;
    572635            $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;
    573646            array_push($itemData, $doshiiItem);
    574647        }
     
    635708                'accept' => 'application/json',
    636709                'Accept-encoding' => 'gzip',
    637                 'x-doshii-writeout' => 'WooCommerce 2.5.2',
     710                'x-doshii-writeout' => 'WooCommerce 2.5.3',
    638711            ),
    639712            'body' => json_encode($doshiiOrderPayload)
  • doshii/trunk/include/woo-order-status.php

    r2817460 r2826771  
    3939                'x-doshii-location-id' => $doshii_options['location_id'].'',
    4040                'content-Type' => 'application/json',
    41                 'x-doshii-writeout' => 'WooCommerce 2.5.2',
     41                'x-doshii-writeout' => 'WooCommerce 2.5.3',
    4242            )
    4343        ));
Note: See TracChangeset for help on using the changeset viewer.