Plugin Directory

Changeset 3257191


Ignore:
Timestamp:
03/17/2025 02:21:05 PM (13 months ago)
Author:
simplercheckout
Message:

Version 1.1.2

Location:
simpler-checkout
Files:
24 edited
1 copied

Legend:

Unmodified
Added
Removed
  • simpler-checkout/tags/1.1.2/README.txt

    r3244572 r3257191  
    55Tested up to: 6.5
    66Requires PHP: 7.0
    7 Stable tag: 1.1.1
     7Stable tag: 1.1.2
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    3535
    3636== Changelog ==
     37
     38== 1.1.2
     39Compat: [WPC Product Bundles for WooCommerce] (https://wordpress.org/plugins/woo-product-bundle/)
     40Compat: [WPC Frequently Bought Together for WooCommerce] (https://wordpress.org/plugins/woo-bought-together/)
    3741
    3842== 1.1.1
  • simpler-checkout/tags/1.1.2/includes/Models/CartItem.php

    r2776966 r3257191  
    2222     */
    2323    private $bundle_configuration;
     24    /**
     25     * @var array
     26     */
     27    private $bundled;
     28    /**
     29     * @var string
     30     */
     31    private $bundle_type;
    2432
    25     public function __construct($product_id, $quantity, $attrs = [], $bundled = [])
     33    public function __construct($product_id, $quantity, $attrs = [], $bundle_configuration = [], $bundled = [], $bundle_type = null)
    2634    {
    2735        $this->product_id              = $product_id;
    2836        $this->quantity                = $quantity;
    2937        $this->attrs                   = $attrs;
    30         $this->bundle_configuration    = $bundled;
     38        $this->bundle_configuration    = $bundle_configuration;
     39        $this->bundled                 = $bundled;
     40        $this->bundle_type             = $bundle_type;
    3141    }
    3242
     
    3646            return new ProductAttribute($el['key'], $el['value']);
    3747        }, $json['attributes'] ?? []);
    38         return new CartItem($json['product_id'], $json['quantity'], $attrs, $json['bundled'] ?? []);
     48        return new CartItem($json['product_id'], $json['quantity'], $attrs, $json['bundle_configuration'] ?? [], $json['bundled'] ?? [], $json['bundle_type'] ?? null);
    3949    }
    4050
     
    8191        return $config;
    8292    }
     93
     94    public function get_bundled()
     95    {
     96        if(!empty($this->bundled)){
     97            foreach ($this->bundled as &$product) {
     98                if (!array_key_exists('attributes', $product)) {
     99                    $product['attributes'] = [];
     100                } else {
     101                    $product['attributes'] = array_reduce($product['attributes'], function ($acc, $el) {
     102                        $acc[$el['key']] = $el['value'];
     103                        return $acc;
     104                    }, []);
     105                }
     106            }
     107        }
     108        return $this->bundled;
     109    }
     110
     111    public function has_bundled()
     112    {
     113        return !empty($this->bundled);
     114    }
     115
     116    public function get_bundle_type()
     117    {
     118        return $this->bundle_type;
     119    }
     120
     121    public function set_bundle_type($bundle_type)
     122    {
     123        $this->bundle_type = $bundle_type;
     124    }
    83125}
  • simpler-checkout/tags/1.1.2/includes/Services/CartHelper.php

    r3111836 r3257191  
    2525    private function add_item_to_cart(CartItem $item)
    2626    {
    27         $product = \wc_get_product($item->get_product_id());
    2827        $productAdded = false;
    29         if (is_a($product, 'WC_Product_Bundle')) {
    30             $productAdded = $this->add_bundle_to_cart($product, $item);
     28        if(!$item->get_bundle_type() && $item->has_bundled()){
     29       
     30            $bundle_type = apply_filters('simplerwc_get_bundle_type_of_the_product', null,\wc_get_product( $item->get_product_id()));
     31           
     32            $item->set_bundle_type($bundle_type);
     33        }
     34        if ($item->get_bundle_type()) {
     35            $productAdded = apply_filters('simplerwc_add_simpler_bundle_to_cart', false, $item);
    3136        } else {
    3237            $productAdded = \WC()->cart->add_to_cart(
     
    3742                apply_filters('simplerwc_get_cart_item_data', [], $item)
    3843            );
    39 
    40             // Woo Product Bundles configured through Linked Products
    41             foreach ($item->get_bundle_configuration() as $bundled) {
    42                 \WC()->cart->add_to_cart(
    43                     $bundled['product_id'],
    44                     $bundled['quantity'],
    45                     NULL,
    46                     $bundled['attributes'],
    47                     apply_filters('simplerwc_get_cart_item_data', ['bundle_sell_of' => $productAdded], $bundled)
    48                 );
    49             }
    50             if (class_exists('\WC_PB_BS_Cart') && method_exists('\WC_PB_BS_Cart', 'load_bundle_sells_into_session')) {
    51                 \WC_PB_BS_Cart::load_bundle_sells_into_session(\WC()->cart);
    52             }
    5344        }
    54 
    5545        if (is_bool($productAdded) && !$productAdded) {
    5646            throw $this->addProductToCartException
    5747                ?: new InvalidProductException(json_encode(WC()->session->get('wc_notices')));
    5848        }
    59 
    6049        do_action('simplerwc_after_add_to_cart', $productAdded, $item);
    6150    }
     51}
    6252
    63     private function add_bundle_to_cart($bundle, $item)
    64     {
    65         // the final bundle configuration to be added to cart
    66         $configuration = [];
    6753
    68         // get bundle configurations
    69         $bundled = \WC_PB_DB::query_bundled_items(array(
    70             'return'    => 'id=>product_id',
    71             'bundle_id' => array($bundle->get_id())
    72         ));
    73 
    74         // try to match the requested configuration with one of the registered bundles
    75         foreach ($item->get_bundle_configuration() as $bundle_config) {
    76             $found = false;
    77             foreach ($bundled as $bundle_id => $product_id) {
    78                 if ($bundle_config['product_id'] == $product_id) {
    79                     $configuration[$bundle_id] = $bundle_config;
    80                     $configuration[$bundle_id]['optional_selected'] = 'yes';
    81                     $found = true;
    82                     break;
    83                 }
    84             }
    85 
    86             // if not found, check if variation
    87             if (!$found) {
    88                 $product = \wc_get_product($bundle_config['product_id']);
    89                 if ($product->is_type('variation')) {
    90                     // if it's a variation try searching again with parent's id
    91                     /** @var \WC_Product_Variable $product */
    92                     foreach ($bundled as $bundle_id => $product_id) {
    93                         if ($product->get_parent_id() == $product_id) {
    94                             $configuration[$bundle_id] = $this->construct_variation_configuration($bundle_config, $product);
    95                             break;
    96                         }
    97                     }
    98                 }
    99             }
    100         }
    101 
    102         // fill configuration keys for not-selected bundled items
    103         foreach ($bundled as $bundle_id => $product_id) {
    104             if (!array_key_exists($bundle_id, $configuration)) {
    105                 $configuration[$bundle_id] = [
    106                     'optional_selected' => 'no'
    107                 ];
    108             }
    109         }
    110 
    111         return \WC_PB()->cart->add_bundle_to_cart(
    112             $item->get_product_id(),
    113             $item->get_quantity(),
    114             $configuration
    115         );
    116     }
    117 
    118     private function construct_variation_configuration($bundle, $product)
    119     {
    120         $c = $bundle;
    121         foreach ($product->get_variation_attributes() as $k => $v) {
    122             if (!array_key_exists($k, $bundle['attributes'])) {
    123                 $c['attributes'][$k] = $v;
    124             }
    125         }
    126         $c['product_id'] = $product->get_parent_id();
    127         $c['variation_id'] = $bundle['product_id'];
    128         $c['optional_selected'] = 'yes';
    129         return $c;
    130     }
    131 }
  • simpler-checkout/tags/1.1.2/includes/Services/QuotationService.php

    r3108447 r3257191  
    6161            $this->add_item_to_cart($item);
    6262        }
    63 
    6463        // apply coupon first to account for coupons that offer free shipping
    6564        $discount = $this->maybe_apply_coupon();
     
    191190        $products = [];
    192191        foreach (WC()->cart->get_cart() as $lineItem) {
     192           
     193            $lineItem = apply_filters('simplerwc_before_create_quoted_product', $lineItem);
     194
    193195            $attributes = [];
    194196            if (!empty($pairs = $lineItem['variation'])) {
     
    197199                }
    198200            }
    199 
     201           
    200202            $products[] = new QuotedProduct(
    201203                $lineItem['variation_id'] ?: $lineItem['product_id'],
  • simpler-checkout/tags/1.1.2/includes/button.php

    r3238494 r3257191  
    218218function simplerwc_prepare_product($product)
    219219{
    220     return [
    221         'items' => [simplerwc_get_product_attributes($product)]
    222     ];
     220    if ($bundle_type = apply_filters('simplerwc_product_is_bundle_container', false,  $product)) {
     221        return ['items' => [simplerwc_get_product_attributes($product,$bundle_type)] ];
     222    }else{
     223        return ['items' => [simplerwc_get_product_attributes($product)] ];
     224    }
    223225}
    224226
     
    229231        'items' => []
    230232    ];
    231 
    232233    if (is_array($coupons) && count($coupons) > 0 && is_string($coupons[0]) && strlen($coupons[0]) > 0) {
    233234        $ret['coupon'] = $coupons[0];
    234235    }
    235 
    236236    foreach ($cart->get_cart_contents() as $cart_item) {
    237237        if (!array_key_exists('data', $cart_item) || !($cart_item['data'] instanceof WC_Product)) {
    238238            continue;
    239239        }
    240 
    241240        if (apply_filters('simplerwc_button_should_ignore_cart_item', false, $cart_item)) {
    242241            continue;
    243242        }
    244 
    245243        // we'll bundle this in its container
    246         if (simplerwc_cart_item_is_bundled($cart_item)) {
     244        if (apply_filters('simplerwc_cart_item_is_bundled', false, $cart_item)) {
    247245            continue;
    248246        }
    249 
    250         if (function_exists('wc_pb_is_bundle_container_cart_item') && \wc_pb_is_bundle_container_cart_item($cart_item)) {
    251             $bundled_items = \wc_pb_get_bundled_cart_items($cart_item);
    252             foreach ($bundled_items as $idx => $item) {
    253                 $bundled_items[$idx]['quantity'] = $item['quantity'] / $cart_item['quantity'];
    254             }
    255             array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item, $bundled_items));
    256         } else {
    257             $bundled_items = [];
    258             $cross_sell_items = $cart_item["bundle_sells"] ?? [];
    259             foreach ($cross_sell_items as $id) {
    260                 $bundled_items[] = $cart->get_cart_item($id);
    261             }
    262             array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item, $bundled_items));
     247        if ($bundle_type = apply_filters('simplerwc_cart_item_is_bundle_container', false,  $cart_item)) {
     248            $bundled_items = apply_filters('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', [], $cart, $cart_item, $bundle_type);
     249            array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item, $bundled_items, $bundle_type));
     250        }else{
     251            array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item));
    263252        }
    264253    }
     
    266255}
    267256
    268 function simplerwc_get_cart_item_attributes($cart_item, $bundled = null)
    269 {
    270     $attrs = simplerwc_get_product_attributes($cart_item['data']);
    271 
     257function simplerwc_get_cart_item_attributes($cart_item, $bundled_cart_items = null, $bundle_type = null)
     258{
     259    $attrs = simplerwc_get_product_attributes($cart_item['data'], $bundle_type);
    272260    if (isset($cart_item['quantity'])) {
    273261        $attrs['quantity'] = $cart_item['quantity'];
    274262    }
    275 
    276263    if (is_a($cart_item['data'], 'WC_Product_Variation')) {
    277264        /*** @var \WC_Product_Variation $product */
    278265        $attrs['attributes'] = array_key_exists('variation', $cart_item) ? $cart_item['variation'] : $product->get_variation_attributes();
    279266    }
    280 
    281     if (isset($bundled) && count($bundled) > 0) {
     267    if (isset($bundled_cart_items) && count($bundled_cart_items) > 0) {
    282268        $attrs['bundled'] = array_values(array_map(function ($el) {
    283269            return simplerwc_get_cart_item_attributes($el);
    284         }, $bundled));
    285     }
    286 
     270        }, $bundled_cart_items));
     271    }
    287272    return $attrs;
    288273}
     
    291276 * @param \WC_Product $product The product to extract information from
    292277 */
    293 function simplerwc_get_product_attributes($product)
     278function simplerwc_get_product_attributes($product,$bundle_type = null)
    294279{
    295280    $attrs = [
     
    311296        /** @var \WC_Product_Variation $product */
    312297        $attrs['attributes'] = apply_filters('simplerwc_button_get_product_attributes', $product->get_variation_attributes(), $product);
    313     } else if (is_a($product, 'WC_Product_Bundle')) {
    314         /** @var \WC_Product_Bundle $product */
    315         $bundled = \WC_PB_DB::query_bundled_items([
    316             'return' => 'id=>product_id',
    317             'bundle_id' => [$product->get_id()]
    318         ]);
    319         $attrs['bundle_configuration'] = array_reduce($bundled, function ($acc, $el) {
    320             $product = \wc_get_product($el);
    321             if (!$product || \is_wp_error($product)) {
    322                 return $acc;
    323             }
    324             $acc[strval($el)] = simplerwc_get_product_attributes($product);
    325             return $acc;
    326         }, []);
    327     }
    328 
     298    }
     299    if($bundle_type){
     300        $attrs['bundle_type'] = $bundle_type;
     301        $attrs['product_type'] = apply_filters('simplerwc_get_product_type_of_the_bundle',$product->get_type(), $bundle_type);
     302        $attrs['bundle_configuration'] = [];
     303        $bundled_products = apply_filters('simplerwc_get_all_products_linked_to_the_bundle_product',[], $product, $bundle_type);
     304        foreach($bundled_products as $bundled_product){
     305            $attrs['bundle_configuration'][strval($bundled_product->get_id())] = simplerwc_get_product_attributes($bundled_product);
     306        }
     307    }
    329308    return $attrs;
    330309}
     
    339318        return in_array('administrator', wp_get_current_user()->roles, true);
    340319    }
    341 
    342320    if (!is_array($excludedRoles = get_option('simplerwc_excluded_user_roles', [])) || !is_array($roles = wp_get_current_user()->roles)) {
    343321        return true;
    344322    }
    345 
    346323    return count(array_intersect($excludedRoles, $roles)) === 0;
    347324}
    348 
    349 function simplerwc_cart_item_is_bundled($item)
    350 {
    351     // check if is bundle product
    352     if (function_exists('wc_pb_is_bundled_cart_item') && \wc_pb_is_bundled_cart_item($item)) {
    353         return true;
    354     }
    355 
    356     if (array_key_exists('bundle_sell_of', $item)) {
    357         return true;
    358     }
    359 
    360     return false;
    361 }
  • simpler-checkout/tags/1.1.2/includes/compat.php

    r3244572 r3257191  
    213213}
    214214add_action('simplerwc_product_controller_request_before', 'simplerwc_rp_wcdpd_set_is_product_feed', 1, 0);
     215
     216
     217
     218
     219// BUNDLES
     220
     221// WC_PB
     222function simplerwc_compat_wc_pb_cart_item_is_bundled($value, $cart_item)
     223{
     224    if (function_exists('wc_pb_is_bundled_cart_item') && \wc_pb_is_bundled_cart_item($cart_item)) {
     225        return true;
     226    }
     227    return $value;
     228}
     229add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_wc_pb_cart_item_is_bundled', 10, 2);
     230
     231function simplerwc_compat_wc_pb_cart_item_is_bundle_container($value, $cart_item)
     232{
     233    if (function_exists('wc_pb_is_bundle_container_cart_item') && \wc_pb_is_bundle_container_cart_item($cart_item)) {
     234        return 'wc_pb';
     235    }
     236    return $value;
     237}
     238add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_wc_pb_cart_item_is_bundle_container', 10, 2);
     239
     240function simplerwc_compat_wc_pb_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type)
     241{
     242    if($bundle_type!='wc_pb') return $value;
     243
     244    if (function_exists('wc_pb_get_bundled_cart_items') ){
     245        $bundled_items = \wc_pb_get_bundled_cart_items($cart_item);
     246        foreach ($bundled_items as $idx => $item) {
     247            $bundled_items[$idx]['quantity'] = $item['quantity'] / $cart_item['quantity'];
     248        }
     249        return $bundled_items;
     250    }
     251
     252    return $value;
     253}
     254add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_wc_pb_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4);
     255
     256function simplerwc_compat_wc_pb_product_is_bundle_container($value, $product)
     257{
     258    if (is_a($product, 'WC_Product_Bundle')) {
     259        return 'wc_pb';
     260    }
     261    return $value;
     262}
     263add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_wc_pb_product_is_bundle_container', 10, 2);
     264
     265function simplerwc_compat_wc_pb_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type)
     266{
     267    if($bundle_type!='wc_pb') return $value;
     268
     269    if (is_a($product, 'WC_Product_Bundle') && class_exists('WC_PB_DB')) {
     270        $bundled_products = \WC_PB_DB::query_bundled_items([
     271            'return' => 'id=>product_id',
     272            'bundle_id' => [$product->get_id()]
     273        ]);
     274        $value = array_reduce($bundled_products, function ($acc, $el) {
     275            $product = \wc_get_product($el);
     276            if (!$product || \is_wp_error($product)) {
     277                return $acc;
     278            }
     279            $acc[] = $product;
     280            return $acc;
     281        }, []);
     282    }
     283    return $value;
     284}
     285add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_wc_pb_get_all_products_linked_to_the_bundle_product', 10, 3);
     286
     287function simplerwc_compat_wc_pb_add_simpler_bundle_to_cart($value, $simpler_item)
     288{
     289    if($simpler_item->get_bundle_type()!='wc_pb') return $value;
     290
     291    if (!class_exists('WC_PB_DB')) return $value;
     292
     293    // the final bundle configuration to be added to cart
     294    $configuration = [];
     295
     296    // get bundle configurations
     297    $bundled = \WC_PB_DB::query_bundled_items(array(
     298        'return'    => 'id=>product_id',
     299        'bundle_id' => array($simpler_item->get_product_id())
     300    ));
     301
     302    // try to match the requested configuration with one of the registered bundles
     303    foreach ($simpler_item->get_bundled() as $bundle_config) {
     304        $found = false;
     305        foreach ($bundled as $bundle_id => $product_id) {
     306            if ($bundle_config['product_id'] == $product_id) {
     307                $configuration[$bundle_id] = $bundle_config;
     308                $configuration[$bundle_id]['optional_selected'] = 'yes';
     309                $found = true;
     310                break;
     311            }
     312        }
     313
     314        // if not found, check if variation
     315        if (!$found) {
     316            $product = \wc_get_product($bundle_config['product_id']);
     317            if ($product->is_type('variation')) {
     318                // if it's a variation try searching again with parent's id
     319                /** @var \WC_Product_Variable $product */
     320                foreach ($bundled as $bundle_id => $product_id) {
     321                    if ($product->get_parent_id() == $product_id) {
     322                        $configuration[$bundle_id] = simplerwc_compat_wc_pb_construct_variation_configuration($bundle_config, $product);
     323                        break;
     324                    }
     325                }
     326            }
     327        }
     328    }
     329
     330    // fill configuration keys for not-selected bundled items
     331    foreach ($bundled as $bundle_id => $product_id) {
     332        if (!array_key_exists($bundle_id, $configuration)) {
     333            $configuration[$bundle_id] = [
     334                'optional_selected' => 'no'
     335            ];
     336        }
     337    }
     338
     339    return \WC_PB()->cart->add_bundle_to_cart(
     340        $simpler_item->get_product_id(),
     341        $simpler_item->get_quantity(),
     342        $configuration
     343    );
     344}
     345function simplerwc_compat_wc_pb_construct_variation_configuration($bundle, $product)
     346{
     347    $c = $bundle;
     348    foreach ($product->get_variation_attributes() as $k => $v) {
     349        if (!array_key_exists($k, $bundle['attributes'])) {
     350            $c['attributes'][$k] = $v;
     351        }
     352    }
     353    $c['product_id'] = $product->get_parent_id();
     354    $c['variation_id'] = $bundle['product_id'];
     355    $c['optional_selected'] = 'yes';
     356    return $c;
     357}
     358add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_wc_pb_add_simpler_bundle_to_cart', 10, 2);
     359
     360function simplerwc_compat_wc_pb_get_product_type_of_the_bundle($value,$bundle_type)
     361{
     362    if($bundle_type=='wc_pb') return 'bundle';
     363    return $value;
     364}
     365add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_wc_pb_get_product_type_of_the_bundle', 10, 2);
     366
     367function simplerwc_compat_wc_pb_get_bundle_type_of_the_product($value,$product)
     368{
     369    if($value) return $value;
     370    if (is_a($product, 'WC_Product_Bundle') && class_exists('WC_PB_DB')) {
     371        return 'wc_pb';
     372    }
     373    return $value;
     374}
     375add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_wc_pb_get_bundle_type_of_the_product', 10, 2);
     376
     377
     378
     379// WPC Smart Bundles
     380function simplerwc_compat_woosb_cart_item_is_bundled($value, $cart_item)
     381{
     382    if (array_key_exists('woosb_parent_id',$cart_item)) {
     383        return true;
     384    }
     385    return $value;
     386}
     387add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_woosb_cart_item_is_bundled', 10, 2);
     388
     389function simplerwc_compat_woosb_cart_item_is_bundle_container($value, $cart_item)
     390{
     391    if (isset($cart_item['woosb_ids']) && !empty($cart_item['woosb_ids'])){
     392        return 'woosb';
     393    }
     394    return $value;
     395}
     396add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_woosb_cart_item_is_bundle_container', 10, 2);
     397
     398function simplerwc_compat_woosb_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type)
     399{
     400    if($bundle_type!='woosb') return $value;
     401
     402    $bundled_items = [];
     403    $bundle_ids = explode(',', $cart_item['woosb_ids']);
     404   
     405    foreach ($bundle_ids as $id) {
     406        foreach ($cart->get_cart_contents() as $item) {
     407            if ($item['product_id'] == $id) {
     408                $bundled_items[] = $item;
     409                break;
     410            }
     411        }
     412    }
     413    return $bundled_items;
     414}
     415add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_woosb_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4);
     416
     417function simplerwc_compat_woosb_product_is_bundle_container($value, $product)
     418{
     419    if (is_a( $product, 'WC_Product_Woosb' )) {
     420        return 'woosb';
     421    }
     422    return $value;
     423}
     424add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_woosb_product_is_bundle_container', 10, 2);
     425
     426function simplerwc_compat_woosb_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type)
     427{
     428    if($bundle_type!='woosb') return $value;
     429
     430    if (is_a( $product, 'WC_Product_Woosb' )) {
     431        $bundle_items = $product->get_meta('woosb_ids');
     432        if (is_array($bundle_items)) {
     433            foreach ($bundle_items as $key => $item) {
     434                $id = isset($item['id']) ? intval($item['id']) : 0;
     435                if ($id > 0) {
     436                    $bundled_product = \wc_get_product($id);
     437                    if ($bundled_product) {
     438                        $value[] = $bundled_product;
     439                    }
     440                }
     441            }
     442        }
     443    }
     444    return $value;
     445}
     446add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_woosb_get_all_products_linked_to_the_bundle_product', 10, 3);
     447
     448function simplerwc_compat_woosb_add_simpler_bundle_to_cart($value, $simpler_item)
     449{
     450    if($simpler_item->get_bundle_type()!='woosb') return $value;
     451
     452    if (!class_exists('WPCleverWoosb')) return $value;
     453
     454    $WPCleverWoosb = new \WPCleverWoosb;
     455    $cart_data = apply_filters('simplerwc_get_cart_item_data', [], $simpler_item);
     456       
     457    $product_id = $simpler_item->get_product_id();
     458    $quantity = $simpler_item->get_quantity();
     459    $variation_id = NULL;
     460    $variation = $simpler_item->get_attributes_array();
     461
     462    $cart_item_data = $WPCleverWoosb->add_cart_item_data($cart_data,$product_id);
     463    if(isset($cart_item_data['woosb_ids'])){
     464        $new_woosb_ids = [];
     465        $woosb_ids = explode(',',$cart_item_data['woosb_ids']);
     466        foreach($woosb_ids as $woosb_id){
     467            list($pid,$pkey,$pqty) = explode('/',$woosb_id);
     468            foreach($simpler_item->get_bundled() as $b_item){
     469                if($pid == $b_item['product_id']){
     470                    $pqty = $b_item['quantity'];
     471                    $new_woosb_id = implode('/',[$pid,$pkey,$pqty]);
     472                    $new_woosb_ids[]=$new_woosb_id;
     473                }
     474            }
     475        }
     476        $cart_item_data['woosb_ids'] = implode(',',$new_woosb_ids);
     477    }
     478
     479    $cart_item_key = WC()->cart->add_to_cart(
     480        $product_id,
     481        $quantity,   
     482        $variation_id, 
     483        $variation, 
     484        $cart_item_data 
     485    );
     486   
     487    $WPCleverWoosb->add_to_cart($cart_item_key, $product_id, $quantity,null,[],$cart_item_data);
     488    return $cart_item_key;
     489}
     490add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_woosb_add_simpler_bundle_to_cart', 10, 2);
     491
     492function simplerwc_compat_woosb_before_create_quoted_product($lineItem)
     493{
     494    if(isset($lineItem['woosb_price'])){
     495        $lineItem['line_total'] = $lineItem['woosb_price'];
     496        $lineItem['line_subtotal'] = $lineItem['woosb_price'];
     497    }
     498    if(isset($lineItem['woosb_parent_id'])){
     499        $lineItem['line_total'] = 0;
     500        $lineItem['line_subtotal'] = 0;
     501    }
     502    return $lineItem;
     503}
     504add_filter('simplerwc_before_create_quoted_product', 'simplerwc_compat_woosb_before_create_quoted_product', 10, 1);
     505
     506function simplerwc_compat_woosb_get_product_type_of_the_bundle($value,$bundle_type)
     507{
     508    if($bundle_type=='woosb') return 'bundle';
     509    return $value;
     510}
     511add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_woosb_get_product_type_of_the_bundle', 10, 2);
     512
     513function simplerwc_compat_woosb_get_bundle_type_of_the_product($value,$product)
     514{
     515    if($value) return $value;
     516    if (is_a( $product, 'WC_Product_Woosb' )) {
     517        return 'woosb';
     518    }
     519    return $value;
     520}
     521add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_woosb_get_bundle_type_of_the_product', 10, 2);
     522
     523
     524
     525// WPC Frequently Brought Together
     526function simplerwc_compat_woobt_cart_item_is_bundled($value, $cart_item)
     527{
     528    if (array_key_exists('woobt_parent_id',$cart_item)) {
     529        return true;
     530    }
     531    return $value;
     532}
     533add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_woobt_cart_item_is_bundled', 10, 2);
     534
     535function simplerwc_compat_woobt_cart_item_is_bundle_container($value, $cart_item)
     536{
     537    if (isset($cart_item['woobt_ids']) && !empty($cart_item['woobt_ids'])){
     538        return 'woobt';
     539    }
     540    return $value;
     541}
     542add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_woobt_cart_item_is_bundle_container', 10, 2);
     543
     544function simplerwc_compat_woobt_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type)
     545{
     546    if($bundle_type!='woobt') return $value;
     547
     548    $bundled_items = [];
     549    $bundle_ids = explode(',', $cart_item['woobt_ids']);
     550   
     551    foreach ($bundle_ids as $bundle_line) {
     552        list($id,$code,$qty) = explode('/',$bundle_line);
     553        foreach ($cart->get_cart_contents() as $item) {
     554            if ($item['product_id'] == $id && isset($item['woobt_parent_id']) && $item['woobt_parent_id']==$cart_item['product_id']) {
     555                $bundled_items[] = $item;
     556                break;
     557            }
     558        }
     559    }
     560    return $bundled_items;
     561}
     562add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_woobt_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4);
     563
     564function simplerwc_compat_woobt_product_is_bundle_container($value, $product)
     565{
     566    $linked_products = get_post_meta($product->get_id(), 'woobt_ids', true);
     567
     568    if (empty($linked_products)) return $value;
     569   
     570    return 'woobt';
     571}
     572add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_woobt_product_is_bundle_container', 10, 2);
     573
     574function simplerwc_compat_woobt_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type)
     575{
     576    if($bundle_type!='woobt') return $value;
     577
     578    $linked_products = get_post_meta($product->get_id(), 'woobt_ids', true);
     579
     580    if (empty($linked_products)) return $value;
     581
     582    $linked_products = maybe_unserialize($linked_products);
     583   
     584    foreach ($linked_products as $key => $item) {
     585        if (isset($item['id'])) {
     586            $product = wc_get_product($item['id']);
     587            if ($product) {
     588                $value[]=$product;
     589            }
     590        }
     591    }
     592    return $value;
     593}
     594add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_woobt_get_all_products_linked_to_the_bundle_product', 10, 3);
     595
     596function simplerwc_compat_woobt_add_simpler_bundle_to_cart($value, $simpler_item)
     597{
     598    if($simpler_item->get_bundle_type()!='woobt') return $value;
     599
     600    $main_product_metadata = apply_filters('simplerwc_get_cart_item_data', [], $simpler_item);
     601   
     602    $main_product_id = $simpler_item->get_product_id();
     603    $main_product_cart_key = WC()->cart->add_to_cart(
     604        $main_product_id,
     605        $simpler_item->get_quantity(),   
     606        null, 
     607        $simpler_item->get_attributes_array(), 
     608        $main_product_metadata
     609    );
     610    $value = $main_product_cart_key;
     611   
     612    if (class_exists('WPCleverWoobt')) {
     613        $WPCleverWoobt = new \WPCleverWoobt;
     614
     615        $main_product_metadata['woobt_ids'] = '';
     616        $ids = [];
     617        $linked_products = $WPCleverWoobt->get_product_items( $main_product_id );
     618        foreach ($linked_products as $linked_key => $linked_product){
     619            foreach($simpler_item->get_bundled() as $simpler_bundled_item){
     620                if($simpler_bundled_item['product_id'] == $linked_product['id']){
     621                    $ids[] = $simpler_bundled_item['product_id'].'/'.$linked_key.'/'.$simpler_bundled_item['quantity'];
     622                }
     623            }
     624        }
     625        $main_product_metadata['woobt_ids']=implode(',',$ids);
     626        $WPCleverWoobt->add_to_cart(
     627            $main_product_cart_key,
     628            $main_product_id,
     629            $simpler_item->get_quantity(),
     630            null,
     631            $simpler_item->get_attributes_array(), 
     632            $main_product_metadata
     633        );
     634        $value = $main_product_cart_key;
     635    }
     636    WC()->cart->calculate_totals();
     637    return $value;
     638}
     639add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_woobt_add_simpler_bundle_to_cart', 10, 2);
     640
     641function simplerwc_compat_woobt_get_product_type_of_the_bundle($value,$bundle_type)
     642{
     643    return $value;
     644}
     645add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_woobt_get_product_type_of_the_bundle', 10, 2);
     646
     647function simplerwc_compat_woobt_get_bundle_type_of_the_product($value,$product)
     648{
     649    if($value) return $value;
     650    $linked_products = get_post_meta($product->get_id(), 'woobt_ids', true);
     651    if (!empty($linked_products)) return 'woobt';
     652    return $value;
     653}
     654add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_woobt_get_bundle_type_of_the_product', 10, 2);
     655
     656
     657
     658// WC Linked products
     659function simplerwc_compat_woocommerce_cart_item_is_bundled($value, $cart_item)
     660{
     661    if (array_key_exists('bundle_sell_of',$cart_item)) {
     662        return true;
     663    }
     664    return $value;
     665}
     666add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_woocommerce_cart_item_is_bundled', 10, 2);
     667
     668function simplerwc_compat_woocommerce_cart_item_is_bundle_container($value, $cart_item)
     669{
     670    if (isset($cart_item['bundle_sells']) && !empty($cart_item['bundle_sells'])){
     671        return 'woocommerce';
     672    }
     673    return $value;
     674}
     675add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_woocommerce_cart_item_is_bundle_container', 10, 2);
     676
     677function simplerwc_compat_woocommerce_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type)
     678{
     679    if($bundle_type!='woocommerce') return $value;
     680
     681    $bundled_items = [];
     682    $cross_sell_items = $cart_item["bundle_sells"] ?? [];
     683    foreach ($cross_sell_items as $id) {
     684        $bundled_items[] = $cart->get_cart_item($id);
     685    }
     686    return $bundled_items;
     687}
     688add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_woocommerce_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4);
     689
     690function simplerwc_compat_woocommerce_product_is_bundle_container($value, $product)
     691{
     692    $linked_products = get_post_meta($product->get_id(), 'bundle_sells', true);
     693
     694    if (empty($linked_products)) return $value;
     695   
     696    return $value;
     697}
     698add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_woocommerce_product_is_bundle_container', 10, 2);
     699
     700function simplerwc_compat_woocommerce_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type)
     701{
     702    if($bundle_type!='woocommerce') return $value;
     703
     704    return $value;
     705}
     706add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_woocommerce_get_all_products_linked_to_the_bundle_product', 10, 3);
     707
     708function simplerwc_compat_woocommerce_add_simpler_bundle_to_cart($value, $simpler_item)
     709{
     710    if($simpler_item->get_bundle_type()!='woocommerce') return $value;
     711
     712    $main_product_cart_key = \WC()->cart->add_to_cart(
     713        $simpler_item->get_product_id(),
     714        $simpler_item->get_quantity(),
     715        NULL,
     716        $simpler_item->get_attributes_array(),
     717        apply_filters('simplerwc_get_cart_item_data', [], $simpler_item)
     718    );
     719
     720    // Woo Product Bundles configured through Linked Products
     721    foreach ($simpler_item->get_bundled() as $bundled) {
     722        \WC()->cart->add_to_cart(
     723            $bundled['product_id'],
     724            $bundled['quantity'],
     725            NULL,
     726            $bundled['attributes'],
     727            apply_filters('simplerwc_get_cart_item_data', ['bundle_sell_of' => $main_product_cart_key], $bundled)
     728        );
     729    }
     730    if (class_exists('\WC_PB_BS_Cart') && method_exists('\WC_PB_BS_Cart', 'load_bundle_sells_into_session')) {
     731        \WC_PB_BS_Cart::load_bundle_sells_into_session(\WC()->cart);
     732    }
     733    return $main_product_cart_key;
     734}
     735add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_woocommerce_add_simpler_bundle_to_cart', 10, 2);
     736
     737function simplerwc_compat_woocommerce_get_product_type_of_the_bundle($value,$bundle_type)
     738{
     739    return $value;
     740}
     741add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_woocommerce_get_product_type_of_the_bundle', 10, 2);
     742
     743function simplerwc_compat_woocommerce_get_bundle_type_of_the_product($value,$product)
     744{
     745    if($value) return $value;
     746    return 'woocommerce';
     747}
     748add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_woocommerce_get_bundle_type_of_the_product', 11, 2);
     749
  • simpler-checkout/tags/1.1.2/includes/constants.php

    r3244572 r3257191  
    11<?php
    22
    3 const SIMPLERWC_VERSION = '1.1.1';
     3const SIMPLERWC_VERSION = '1.1.2';
    44
    55function simplerwc_get_sdk_uri()
  • simpler-checkout/tags/1.1.2/simpler.php

    r3244572 r3257191  
    88 * Description: Simpler Checkout lets your customers complete their purchases in seconds, with any payment method they want, in any device or browser and without a password.
    99 * Tags: woocommerce, checkout, payments, conversion rate
    10  * Version: 1.1.1
     10 * Version: 1.1.2
    1111 * Requires at least: 5.1
    1212 * Tested up to: 6.3.1
  • simpler-checkout/tags/1.1.2/vendor/autoload.php

    r3244572 r3257191  
    55require_once __DIR__ . '/composer/autoload_real.php';
    66
    7 return ComposerAutoloaderInit0250069f9335df0d3d59ba9ce9dcfb67::getLoader();
     7return ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa::getLoader();
  • simpler-checkout/tags/1.1.2/vendor/composer/autoload_real.php

    r3244572 r3257191  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit0250069f9335df0d3d59ba9ce9dcfb67
     5class ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa
    66{
    77    private static $loader;
     
    2525        require __DIR__ . '/platform_check.php';
    2626
    27         spl_autoload_register(array('ComposerAutoloaderInit0250069f9335df0d3d59ba9ce9dcfb67', 'loadClassLoader'), true, true);
     27        spl_autoload_register(array('ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa', 'loadClassLoader'), true, true);
    2828        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
    29         spl_autoload_unregister(array('ComposerAutoloaderInit0250069f9335df0d3d59ba9ce9dcfb67', 'loadClassLoader'));
     29        spl_autoload_unregister(array('ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa', 'loadClassLoader'));
    3030
    3131        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
     
    3333            require __DIR__ . '/autoload_static.php';
    3434
    35             call_user_func(\Composer\Autoload\ComposerStaticInit0250069f9335df0d3d59ba9ce9dcfb67::getInitializer($loader));
     35            call_user_func(\Composer\Autoload\ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::getInitializer($loader));
    3636        } else {
    3737            $map = require __DIR__ . '/autoload_namespaces.php';
  • simpler-checkout/tags/1.1.2/vendor/composer/autoload_static.php

    r3244572 r3257191  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit0250069f9335df0d3d59ba9ce9dcfb67
     7class ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa
    88{
    99    public static $prefixLengthsPsr4 = array (
     
    8686    {
    8787        return \Closure::bind(function () use ($loader) {
    88             $loader->prefixLengthsPsr4 = ComposerStaticInit0250069f9335df0d3d59ba9ce9dcfb67::$prefixLengthsPsr4;
    89             $loader->prefixDirsPsr4 = ComposerStaticInit0250069f9335df0d3d59ba9ce9dcfb67::$prefixDirsPsr4;
    90             $loader->classMap = ComposerStaticInit0250069f9335df0d3d59ba9ce9dcfb67::$classMap;
     88            $loader->prefixLengthsPsr4 = ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::$prefixLengthsPsr4;
     89            $loader->prefixDirsPsr4 = ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::$prefixDirsPsr4;
     90            $loader->classMap = ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::$classMap;
    9191
    9292        }, null, ClassLoader::class);
  • simpler-checkout/tags/1.1.2/vendor/composer/installed.php

    r3244572 r3257191  
    11<?php return array(
    22    'root' => array(
    3         'pretty_version' => '1.1.1',
    4         'version' => '1.1.1.0',
     3        'pretty_version' => '1.1.2',
     4        'version' => '1.1.2.0',
    55        'type' => 'wordpress-plugin',
    66        'install_path' => __DIR__ . '/../../',
    77        'aliases' => array(),
    8         'reference' => 'bb55c256e100142e4cc55de1af03ca9bcf581777',
     8        'reference' => '8b7d98f2bf87df11c50d0440d830606ab05ad7ef',
    99        'name' => 'simpler-checkout/woo',
    1010        'dev' => false,
     
    1212    'versions' => array(
    1313        'simpler-checkout/woo' => array(
    14             'pretty_version' => '1.1.1',
    15             'version' => '1.1.1.0',
     14            'pretty_version' => '1.1.2',
     15            'version' => '1.1.2.0',
    1616            'type' => 'wordpress-plugin',
    1717            'install_path' => __DIR__ . '/../../',
    1818            'aliases' => array(),
    19             'reference' => 'bb55c256e100142e4cc55de1af03ca9bcf581777',
     19            'reference' => '8b7d98f2bf87df11c50d0440d830606ab05ad7ef',
    2020            'dev_requirement' => false,
    2121        ),
  • simpler-checkout/trunk/README.txt

    r3244572 r3257191  
    55Tested up to: 6.5
    66Requires PHP: 7.0
    7 Stable tag: 1.1.1
     7Stable tag: 1.1.2
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    3535
    3636== Changelog ==
     37
     38== 1.1.2
     39Compat: [WPC Product Bundles for WooCommerce] (https://wordpress.org/plugins/woo-product-bundle/)
     40Compat: [WPC Frequently Bought Together for WooCommerce] (https://wordpress.org/plugins/woo-bought-together/)
    3741
    3842== 1.1.1
  • simpler-checkout/trunk/includes/Models/CartItem.php

    r2776966 r3257191  
    2222     */
    2323    private $bundle_configuration;
     24    /**
     25     * @var array
     26     */
     27    private $bundled;
     28    /**
     29     * @var string
     30     */
     31    private $bundle_type;
    2432
    25     public function __construct($product_id, $quantity, $attrs = [], $bundled = [])
     33    public function __construct($product_id, $quantity, $attrs = [], $bundle_configuration = [], $bundled = [], $bundle_type = null)
    2634    {
    2735        $this->product_id              = $product_id;
    2836        $this->quantity                = $quantity;
    2937        $this->attrs                   = $attrs;
    30         $this->bundle_configuration    = $bundled;
     38        $this->bundle_configuration    = $bundle_configuration;
     39        $this->bundled                 = $bundled;
     40        $this->bundle_type             = $bundle_type;
    3141    }
    3242
     
    3646            return new ProductAttribute($el['key'], $el['value']);
    3747        }, $json['attributes'] ?? []);
    38         return new CartItem($json['product_id'], $json['quantity'], $attrs, $json['bundled'] ?? []);
     48        return new CartItem($json['product_id'], $json['quantity'], $attrs, $json['bundle_configuration'] ?? [], $json['bundled'] ?? [], $json['bundle_type'] ?? null);
    3949    }
    4050
     
    8191        return $config;
    8292    }
     93
     94    public function get_bundled()
     95    {
     96        if(!empty($this->bundled)){
     97            foreach ($this->bundled as &$product) {
     98                if (!array_key_exists('attributes', $product)) {
     99                    $product['attributes'] = [];
     100                } else {
     101                    $product['attributes'] = array_reduce($product['attributes'], function ($acc, $el) {
     102                        $acc[$el['key']] = $el['value'];
     103                        return $acc;
     104                    }, []);
     105                }
     106            }
     107        }
     108        return $this->bundled;
     109    }
     110
     111    public function has_bundled()
     112    {
     113        return !empty($this->bundled);
     114    }
     115
     116    public function get_bundle_type()
     117    {
     118        return $this->bundle_type;
     119    }
     120
     121    public function set_bundle_type($bundle_type)
     122    {
     123        $this->bundle_type = $bundle_type;
     124    }
    83125}
  • simpler-checkout/trunk/includes/Services/CartHelper.php

    r3111836 r3257191  
    2525    private function add_item_to_cart(CartItem $item)
    2626    {
    27         $product = \wc_get_product($item->get_product_id());
    2827        $productAdded = false;
    29         if (is_a($product, 'WC_Product_Bundle')) {
    30             $productAdded = $this->add_bundle_to_cart($product, $item);
     28        if(!$item->get_bundle_type() && $item->has_bundled()){
     29       
     30            $bundle_type = apply_filters('simplerwc_get_bundle_type_of_the_product', null,\wc_get_product( $item->get_product_id()));
     31           
     32            $item->set_bundle_type($bundle_type);
     33        }
     34        if ($item->get_bundle_type()) {
     35            $productAdded = apply_filters('simplerwc_add_simpler_bundle_to_cart', false, $item);
    3136        } else {
    3237            $productAdded = \WC()->cart->add_to_cart(
     
    3742                apply_filters('simplerwc_get_cart_item_data', [], $item)
    3843            );
    39 
    40             // Woo Product Bundles configured through Linked Products
    41             foreach ($item->get_bundle_configuration() as $bundled) {
    42                 \WC()->cart->add_to_cart(
    43                     $bundled['product_id'],
    44                     $bundled['quantity'],
    45                     NULL,
    46                     $bundled['attributes'],
    47                     apply_filters('simplerwc_get_cart_item_data', ['bundle_sell_of' => $productAdded], $bundled)
    48                 );
    49             }
    50             if (class_exists('\WC_PB_BS_Cart') && method_exists('\WC_PB_BS_Cart', 'load_bundle_sells_into_session')) {
    51                 \WC_PB_BS_Cart::load_bundle_sells_into_session(\WC()->cart);
    52             }
    5344        }
    54 
    5545        if (is_bool($productAdded) && !$productAdded) {
    5646            throw $this->addProductToCartException
    5747                ?: new InvalidProductException(json_encode(WC()->session->get('wc_notices')));
    5848        }
    59 
    6049        do_action('simplerwc_after_add_to_cart', $productAdded, $item);
    6150    }
     51}
    6252
    63     private function add_bundle_to_cart($bundle, $item)
    64     {
    65         // the final bundle configuration to be added to cart
    66         $configuration = [];
    6753
    68         // get bundle configurations
    69         $bundled = \WC_PB_DB::query_bundled_items(array(
    70             'return'    => 'id=>product_id',
    71             'bundle_id' => array($bundle->get_id())
    72         ));
    73 
    74         // try to match the requested configuration with one of the registered bundles
    75         foreach ($item->get_bundle_configuration() as $bundle_config) {
    76             $found = false;
    77             foreach ($bundled as $bundle_id => $product_id) {
    78                 if ($bundle_config['product_id'] == $product_id) {
    79                     $configuration[$bundle_id] = $bundle_config;
    80                     $configuration[$bundle_id]['optional_selected'] = 'yes';
    81                     $found = true;
    82                     break;
    83                 }
    84             }
    85 
    86             // if not found, check if variation
    87             if (!$found) {
    88                 $product = \wc_get_product($bundle_config['product_id']);
    89                 if ($product->is_type('variation')) {
    90                     // if it's a variation try searching again with parent's id
    91                     /** @var \WC_Product_Variable $product */
    92                     foreach ($bundled as $bundle_id => $product_id) {
    93                         if ($product->get_parent_id() == $product_id) {
    94                             $configuration[$bundle_id] = $this->construct_variation_configuration($bundle_config, $product);
    95                             break;
    96                         }
    97                     }
    98                 }
    99             }
    100         }
    101 
    102         // fill configuration keys for not-selected bundled items
    103         foreach ($bundled as $bundle_id => $product_id) {
    104             if (!array_key_exists($bundle_id, $configuration)) {
    105                 $configuration[$bundle_id] = [
    106                     'optional_selected' => 'no'
    107                 ];
    108             }
    109         }
    110 
    111         return \WC_PB()->cart->add_bundle_to_cart(
    112             $item->get_product_id(),
    113             $item->get_quantity(),
    114             $configuration
    115         );
    116     }
    117 
    118     private function construct_variation_configuration($bundle, $product)
    119     {
    120         $c = $bundle;
    121         foreach ($product->get_variation_attributes() as $k => $v) {
    122             if (!array_key_exists($k, $bundle['attributes'])) {
    123                 $c['attributes'][$k] = $v;
    124             }
    125         }
    126         $c['product_id'] = $product->get_parent_id();
    127         $c['variation_id'] = $bundle['product_id'];
    128         $c['optional_selected'] = 'yes';
    129         return $c;
    130     }
    131 }
  • simpler-checkout/trunk/includes/Services/QuotationService.php

    r3108447 r3257191  
    6161            $this->add_item_to_cart($item);
    6262        }
    63 
    6463        // apply coupon first to account for coupons that offer free shipping
    6564        $discount = $this->maybe_apply_coupon();
     
    191190        $products = [];
    192191        foreach (WC()->cart->get_cart() as $lineItem) {
     192           
     193            $lineItem = apply_filters('simplerwc_before_create_quoted_product', $lineItem);
     194
    193195            $attributes = [];
    194196            if (!empty($pairs = $lineItem['variation'])) {
     
    197199                }
    198200            }
    199 
     201           
    200202            $products[] = new QuotedProduct(
    201203                $lineItem['variation_id'] ?: $lineItem['product_id'],
  • simpler-checkout/trunk/includes/button.php

    r3238494 r3257191  
    218218function simplerwc_prepare_product($product)
    219219{
    220     return [
    221         'items' => [simplerwc_get_product_attributes($product)]
    222     ];
     220    if ($bundle_type = apply_filters('simplerwc_product_is_bundle_container', false,  $product)) {
     221        return ['items' => [simplerwc_get_product_attributes($product,$bundle_type)] ];
     222    }else{
     223        return ['items' => [simplerwc_get_product_attributes($product)] ];
     224    }
    223225}
    224226
     
    229231        'items' => []
    230232    ];
    231 
    232233    if (is_array($coupons) && count($coupons) > 0 && is_string($coupons[0]) && strlen($coupons[0]) > 0) {
    233234        $ret['coupon'] = $coupons[0];
    234235    }
    235 
    236236    foreach ($cart->get_cart_contents() as $cart_item) {
    237237        if (!array_key_exists('data', $cart_item) || !($cart_item['data'] instanceof WC_Product)) {
    238238            continue;
    239239        }
    240 
    241240        if (apply_filters('simplerwc_button_should_ignore_cart_item', false, $cart_item)) {
    242241            continue;
    243242        }
    244 
    245243        // we'll bundle this in its container
    246         if (simplerwc_cart_item_is_bundled($cart_item)) {
     244        if (apply_filters('simplerwc_cart_item_is_bundled', false, $cart_item)) {
    247245            continue;
    248246        }
    249 
    250         if (function_exists('wc_pb_is_bundle_container_cart_item') && \wc_pb_is_bundle_container_cart_item($cart_item)) {
    251             $bundled_items = \wc_pb_get_bundled_cart_items($cart_item);
    252             foreach ($bundled_items as $idx => $item) {
    253                 $bundled_items[$idx]['quantity'] = $item['quantity'] / $cart_item['quantity'];
    254             }
    255             array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item, $bundled_items));
    256         } else {
    257             $bundled_items = [];
    258             $cross_sell_items = $cart_item["bundle_sells"] ?? [];
    259             foreach ($cross_sell_items as $id) {
    260                 $bundled_items[] = $cart->get_cart_item($id);
    261             }
    262             array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item, $bundled_items));
     247        if ($bundle_type = apply_filters('simplerwc_cart_item_is_bundle_container', false,  $cart_item)) {
     248            $bundled_items = apply_filters('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', [], $cart, $cart_item, $bundle_type);
     249            array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item, $bundled_items, $bundle_type));
     250        }else{
     251            array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item));
    263252        }
    264253    }
     
    266255}
    267256
    268 function simplerwc_get_cart_item_attributes($cart_item, $bundled = null)
    269 {
    270     $attrs = simplerwc_get_product_attributes($cart_item['data']);
    271 
     257function simplerwc_get_cart_item_attributes($cart_item, $bundled_cart_items = null, $bundle_type = null)
     258{
     259    $attrs = simplerwc_get_product_attributes($cart_item['data'], $bundle_type);
    272260    if (isset($cart_item['quantity'])) {
    273261        $attrs['quantity'] = $cart_item['quantity'];
    274262    }
    275 
    276263    if (is_a($cart_item['data'], 'WC_Product_Variation')) {
    277264        /*** @var \WC_Product_Variation $product */
    278265        $attrs['attributes'] = array_key_exists('variation', $cart_item) ? $cart_item['variation'] : $product->get_variation_attributes();
    279266    }
    280 
    281     if (isset($bundled) && count($bundled) > 0) {
     267    if (isset($bundled_cart_items) && count($bundled_cart_items) > 0) {
    282268        $attrs['bundled'] = array_values(array_map(function ($el) {
    283269            return simplerwc_get_cart_item_attributes($el);
    284         }, $bundled));
    285     }
    286 
     270        }, $bundled_cart_items));
     271    }
    287272    return $attrs;
    288273}
     
    291276 * @param \WC_Product $product The product to extract information from
    292277 */
    293 function simplerwc_get_product_attributes($product)
     278function simplerwc_get_product_attributes($product,$bundle_type = null)
    294279{
    295280    $attrs = [
     
    311296        /** @var \WC_Product_Variation $product */
    312297        $attrs['attributes'] = apply_filters('simplerwc_button_get_product_attributes', $product->get_variation_attributes(), $product);
    313     } else if (is_a($product, 'WC_Product_Bundle')) {
    314         /** @var \WC_Product_Bundle $product */
    315         $bundled = \WC_PB_DB::query_bundled_items([
    316             'return' => 'id=>product_id',
    317             'bundle_id' => [$product->get_id()]
    318         ]);
    319         $attrs['bundle_configuration'] = array_reduce($bundled, function ($acc, $el) {
    320             $product = \wc_get_product($el);
    321             if (!$product || \is_wp_error($product)) {
    322                 return $acc;
    323             }
    324             $acc[strval($el)] = simplerwc_get_product_attributes($product);
    325             return $acc;
    326         }, []);
    327     }
    328 
     298    }
     299    if($bundle_type){
     300        $attrs['bundle_type'] = $bundle_type;
     301        $attrs['product_type'] = apply_filters('simplerwc_get_product_type_of_the_bundle',$product->get_type(), $bundle_type);
     302        $attrs['bundle_configuration'] = [];
     303        $bundled_products = apply_filters('simplerwc_get_all_products_linked_to_the_bundle_product',[], $product, $bundle_type);
     304        foreach($bundled_products as $bundled_product){
     305            $attrs['bundle_configuration'][strval($bundled_product->get_id())] = simplerwc_get_product_attributes($bundled_product);
     306        }
     307    }
    329308    return $attrs;
    330309}
     
    339318        return in_array('administrator', wp_get_current_user()->roles, true);
    340319    }
    341 
    342320    if (!is_array($excludedRoles = get_option('simplerwc_excluded_user_roles', [])) || !is_array($roles = wp_get_current_user()->roles)) {
    343321        return true;
    344322    }
    345 
    346323    return count(array_intersect($excludedRoles, $roles)) === 0;
    347324}
    348 
    349 function simplerwc_cart_item_is_bundled($item)
    350 {
    351     // check if is bundle product
    352     if (function_exists('wc_pb_is_bundled_cart_item') && \wc_pb_is_bundled_cart_item($item)) {
    353         return true;
    354     }
    355 
    356     if (array_key_exists('bundle_sell_of', $item)) {
    357         return true;
    358     }
    359 
    360     return false;
    361 }
  • simpler-checkout/trunk/includes/compat.php

    r3244572 r3257191  
    213213}
    214214add_action('simplerwc_product_controller_request_before', 'simplerwc_rp_wcdpd_set_is_product_feed', 1, 0);
     215
     216
     217
     218
     219// BUNDLES
     220
     221// WC_PB
     222function simplerwc_compat_wc_pb_cart_item_is_bundled($value, $cart_item)
     223{
     224    if (function_exists('wc_pb_is_bundled_cart_item') && \wc_pb_is_bundled_cart_item($cart_item)) {
     225        return true;
     226    }
     227    return $value;
     228}
     229add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_wc_pb_cart_item_is_bundled', 10, 2);
     230
     231function simplerwc_compat_wc_pb_cart_item_is_bundle_container($value, $cart_item)
     232{
     233    if (function_exists('wc_pb_is_bundle_container_cart_item') && \wc_pb_is_bundle_container_cart_item($cart_item)) {
     234        return 'wc_pb';
     235    }
     236    return $value;
     237}
     238add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_wc_pb_cart_item_is_bundle_container', 10, 2);
     239
     240function simplerwc_compat_wc_pb_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type)
     241{
     242    if($bundle_type!='wc_pb') return $value;
     243
     244    if (function_exists('wc_pb_get_bundled_cart_items') ){
     245        $bundled_items = \wc_pb_get_bundled_cart_items($cart_item);
     246        foreach ($bundled_items as $idx => $item) {
     247            $bundled_items[$idx]['quantity'] = $item['quantity'] / $cart_item['quantity'];
     248        }
     249        return $bundled_items;
     250    }
     251
     252    return $value;
     253}
     254add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_wc_pb_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4);
     255
     256function simplerwc_compat_wc_pb_product_is_bundle_container($value, $product)
     257{
     258    if (is_a($product, 'WC_Product_Bundle')) {
     259        return 'wc_pb';
     260    }
     261    return $value;
     262}
     263add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_wc_pb_product_is_bundle_container', 10, 2);
     264
     265function simplerwc_compat_wc_pb_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type)
     266{
     267    if($bundle_type!='wc_pb') return $value;
     268
     269    if (is_a($product, 'WC_Product_Bundle') && class_exists('WC_PB_DB')) {
     270        $bundled_products = \WC_PB_DB::query_bundled_items([
     271            'return' => 'id=>product_id',
     272            'bundle_id' => [$product->get_id()]
     273        ]);
     274        $value = array_reduce($bundled_products, function ($acc, $el) {
     275            $product = \wc_get_product($el);
     276            if (!$product || \is_wp_error($product)) {
     277                return $acc;
     278            }
     279            $acc[] = $product;
     280            return $acc;
     281        }, []);
     282    }
     283    return $value;
     284}
     285add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_wc_pb_get_all_products_linked_to_the_bundle_product', 10, 3);
     286
     287function simplerwc_compat_wc_pb_add_simpler_bundle_to_cart($value, $simpler_item)
     288{
     289    if($simpler_item->get_bundle_type()!='wc_pb') return $value;
     290
     291    if (!class_exists('WC_PB_DB')) return $value;
     292
     293    // the final bundle configuration to be added to cart
     294    $configuration = [];
     295
     296    // get bundle configurations
     297    $bundled = \WC_PB_DB::query_bundled_items(array(
     298        'return'    => 'id=>product_id',
     299        'bundle_id' => array($simpler_item->get_product_id())
     300    ));
     301
     302    // try to match the requested configuration with one of the registered bundles
     303    foreach ($simpler_item->get_bundled() as $bundle_config) {
     304        $found = false;
     305        foreach ($bundled as $bundle_id => $product_id) {
     306            if ($bundle_config['product_id'] == $product_id) {
     307                $configuration[$bundle_id] = $bundle_config;
     308                $configuration[$bundle_id]['optional_selected'] = 'yes';
     309                $found = true;
     310                break;
     311            }
     312        }
     313
     314        // if not found, check if variation
     315        if (!$found) {
     316            $product = \wc_get_product($bundle_config['product_id']);
     317            if ($product->is_type('variation')) {
     318                // if it's a variation try searching again with parent's id
     319                /** @var \WC_Product_Variable $product */
     320                foreach ($bundled as $bundle_id => $product_id) {
     321                    if ($product->get_parent_id() == $product_id) {
     322                        $configuration[$bundle_id] = simplerwc_compat_wc_pb_construct_variation_configuration($bundle_config, $product);
     323                        break;
     324                    }
     325                }
     326            }
     327        }
     328    }
     329
     330    // fill configuration keys for not-selected bundled items
     331    foreach ($bundled as $bundle_id => $product_id) {
     332        if (!array_key_exists($bundle_id, $configuration)) {
     333            $configuration[$bundle_id] = [
     334                'optional_selected' => 'no'
     335            ];
     336        }
     337    }
     338
     339    return \WC_PB()->cart->add_bundle_to_cart(
     340        $simpler_item->get_product_id(),
     341        $simpler_item->get_quantity(),
     342        $configuration
     343    );
     344}
     345function simplerwc_compat_wc_pb_construct_variation_configuration($bundle, $product)
     346{
     347    $c = $bundle;
     348    foreach ($product->get_variation_attributes() as $k => $v) {
     349        if (!array_key_exists($k, $bundle['attributes'])) {
     350            $c['attributes'][$k] = $v;
     351        }
     352    }
     353    $c['product_id'] = $product->get_parent_id();
     354    $c['variation_id'] = $bundle['product_id'];
     355    $c['optional_selected'] = 'yes';
     356    return $c;
     357}
     358add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_wc_pb_add_simpler_bundle_to_cart', 10, 2);
     359
     360function simplerwc_compat_wc_pb_get_product_type_of_the_bundle($value,$bundle_type)
     361{
     362    if($bundle_type=='wc_pb') return 'bundle';
     363    return $value;
     364}
     365add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_wc_pb_get_product_type_of_the_bundle', 10, 2);
     366
     367function simplerwc_compat_wc_pb_get_bundle_type_of_the_product($value,$product)
     368{
     369    if($value) return $value;
     370    if (is_a($product, 'WC_Product_Bundle') && class_exists('WC_PB_DB')) {
     371        return 'wc_pb';
     372    }
     373    return $value;
     374}
     375add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_wc_pb_get_bundle_type_of_the_product', 10, 2);
     376
     377
     378
     379// WPC Smart Bundles
     380function simplerwc_compat_woosb_cart_item_is_bundled($value, $cart_item)
     381{
     382    if (array_key_exists('woosb_parent_id',$cart_item)) {
     383        return true;
     384    }
     385    return $value;
     386}
     387add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_woosb_cart_item_is_bundled', 10, 2);
     388
     389function simplerwc_compat_woosb_cart_item_is_bundle_container($value, $cart_item)
     390{
     391    if (isset($cart_item['woosb_ids']) && !empty($cart_item['woosb_ids'])){
     392        return 'woosb';
     393    }
     394    return $value;
     395}
     396add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_woosb_cart_item_is_bundle_container', 10, 2);
     397
     398function simplerwc_compat_woosb_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type)
     399{
     400    if($bundle_type!='woosb') return $value;
     401
     402    $bundled_items = [];
     403    $bundle_ids = explode(',', $cart_item['woosb_ids']);
     404   
     405    foreach ($bundle_ids as $id) {
     406        foreach ($cart->get_cart_contents() as $item) {
     407            if ($item['product_id'] == $id) {
     408                $bundled_items[] = $item;
     409                break;
     410            }
     411        }
     412    }
     413    return $bundled_items;
     414}
     415add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_woosb_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4);
     416
     417function simplerwc_compat_woosb_product_is_bundle_container($value, $product)
     418{
     419    if (is_a( $product, 'WC_Product_Woosb' )) {
     420        return 'woosb';
     421    }
     422    return $value;
     423}
     424add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_woosb_product_is_bundle_container', 10, 2);
     425
     426function simplerwc_compat_woosb_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type)
     427{
     428    if($bundle_type!='woosb') return $value;
     429
     430    if (is_a( $product, 'WC_Product_Woosb' )) {
     431        $bundle_items = $product->get_meta('woosb_ids');
     432        if (is_array($bundle_items)) {
     433            foreach ($bundle_items as $key => $item) {
     434                $id = isset($item['id']) ? intval($item['id']) : 0;
     435                if ($id > 0) {
     436                    $bundled_product = \wc_get_product($id);
     437                    if ($bundled_product) {
     438                        $value[] = $bundled_product;
     439                    }
     440                }
     441            }
     442        }
     443    }
     444    return $value;
     445}
     446add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_woosb_get_all_products_linked_to_the_bundle_product', 10, 3);
     447
     448function simplerwc_compat_woosb_add_simpler_bundle_to_cart($value, $simpler_item)
     449{
     450    if($simpler_item->get_bundle_type()!='woosb') return $value;
     451
     452    if (!class_exists('WPCleverWoosb')) return $value;
     453
     454    $WPCleverWoosb = new \WPCleverWoosb;
     455    $cart_data = apply_filters('simplerwc_get_cart_item_data', [], $simpler_item);
     456       
     457    $product_id = $simpler_item->get_product_id();
     458    $quantity = $simpler_item->get_quantity();
     459    $variation_id = NULL;
     460    $variation = $simpler_item->get_attributes_array();
     461
     462    $cart_item_data = $WPCleverWoosb->add_cart_item_data($cart_data,$product_id);
     463    if(isset($cart_item_data['woosb_ids'])){
     464        $new_woosb_ids = [];
     465        $woosb_ids = explode(',',$cart_item_data['woosb_ids']);
     466        foreach($woosb_ids as $woosb_id){
     467            list($pid,$pkey,$pqty) = explode('/',$woosb_id);
     468            foreach($simpler_item->get_bundled() as $b_item){
     469                if($pid == $b_item['product_id']){
     470                    $pqty = $b_item['quantity'];
     471                    $new_woosb_id = implode('/',[$pid,$pkey,$pqty]);
     472                    $new_woosb_ids[]=$new_woosb_id;
     473                }
     474            }
     475        }
     476        $cart_item_data['woosb_ids'] = implode(',',$new_woosb_ids);
     477    }
     478
     479    $cart_item_key = WC()->cart->add_to_cart(
     480        $product_id,
     481        $quantity,   
     482        $variation_id, 
     483        $variation, 
     484        $cart_item_data 
     485    );
     486   
     487    $WPCleverWoosb->add_to_cart($cart_item_key, $product_id, $quantity,null,[],$cart_item_data);
     488    return $cart_item_key;
     489}
     490add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_woosb_add_simpler_bundle_to_cart', 10, 2);
     491
     492function simplerwc_compat_woosb_before_create_quoted_product($lineItem)
     493{
     494    if(isset($lineItem['woosb_price'])){
     495        $lineItem['line_total'] = $lineItem['woosb_price'];
     496        $lineItem['line_subtotal'] = $lineItem['woosb_price'];
     497    }
     498    if(isset($lineItem['woosb_parent_id'])){
     499        $lineItem['line_total'] = 0;
     500        $lineItem['line_subtotal'] = 0;
     501    }
     502    return $lineItem;
     503}
     504add_filter('simplerwc_before_create_quoted_product', 'simplerwc_compat_woosb_before_create_quoted_product', 10, 1);
     505
     506function simplerwc_compat_woosb_get_product_type_of_the_bundle($value,$bundle_type)
     507{
     508    if($bundle_type=='woosb') return 'bundle';
     509    return $value;
     510}
     511add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_woosb_get_product_type_of_the_bundle', 10, 2);
     512
     513function simplerwc_compat_woosb_get_bundle_type_of_the_product($value,$product)
     514{
     515    if($value) return $value;
     516    if (is_a( $product, 'WC_Product_Woosb' )) {
     517        return 'woosb';
     518    }
     519    return $value;
     520}
     521add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_woosb_get_bundle_type_of_the_product', 10, 2);
     522
     523
     524
     525// WPC Frequently Brought Together
     526function simplerwc_compat_woobt_cart_item_is_bundled($value, $cart_item)
     527{
     528    if (array_key_exists('woobt_parent_id',$cart_item)) {
     529        return true;
     530    }
     531    return $value;
     532}
     533add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_woobt_cart_item_is_bundled', 10, 2);
     534
     535function simplerwc_compat_woobt_cart_item_is_bundle_container($value, $cart_item)
     536{
     537    if (isset($cart_item['woobt_ids']) && !empty($cart_item['woobt_ids'])){
     538        return 'woobt';
     539    }
     540    return $value;
     541}
     542add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_woobt_cart_item_is_bundle_container', 10, 2);
     543
     544function simplerwc_compat_woobt_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type)
     545{
     546    if($bundle_type!='woobt') return $value;
     547
     548    $bundled_items = [];
     549    $bundle_ids = explode(',', $cart_item['woobt_ids']);
     550   
     551    foreach ($bundle_ids as $bundle_line) {
     552        list($id,$code,$qty) = explode('/',$bundle_line);
     553        foreach ($cart->get_cart_contents() as $item) {
     554            if ($item['product_id'] == $id && isset($item['woobt_parent_id']) && $item['woobt_parent_id']==$cart_item['product_id']) {
     555                $bundled_items[] = $item;
     556                break;
     557            }
     558        }
     559    }
     560    return $bundled_items;
     561}
     562add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_woobt_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4);
     563
     564function simplerwc_compat_woobt_product_is_bundle_container($value, $product)
     565{
     566    $linked_products = get_post_meta($product->get_id(), 'woobt_ids', true);
     567
     568    if (empty($linked_products)) return $value;
     569   
     570    return 'woobt';
     571}
     572add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_woobt_product_is_bundle_container', 10, 2);
     573
     574function simplerwc_compat_woobt_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type)
     575{
     576    if($bundle_type!='woobt') return $value;
     577
     578    $linked_products = get_post_meta($product->get_id(), 'woobt_ids', true);
     579
     580    if (empty($linked_products)) return $value;
     581
     582    $linked_products = maybe_unserialize($linked_products);
     583   
     584    foreach ($linked_products as $key => $item) {
     585        if (isset($item['id'])) {
     586            $product = wc_get_product($item['id']);
     587            if ($product) {
     588                $value[]=$product;
     589            }
     590        }
     591    }
     592    return $value;
     593}
     594add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_woobt_get_all_products_linked_to_the_bundle_product', 10, 3);
     595
     596function simplerwc_compat_woobt_add_simpler_bundle_to_cart($value, $simpler_item)
     597{
     598    if($simpler_item->get_bundle_type()!='woobt') return $value;
     599
     600    $main_product_metadata = apply_filters('simplerwc_get_cart_item_data', [], $simpler_item);
     601   
     602    $main_product_id = $simpler_item->get_product_id();
     603    $main_product_cart_key = WC()->cart->add_to_cart(
     604        $main_product_id,
     605        $simpler_item->get_quantity(),   
     606        null, 
     607        $simpler_item->get_attributes_array(), 
     608        $main_product_metadata
     609    );
     610    $value = $main_product_cart_key;
     611   
     612    if (class_exists('WPCleverWoobt')) {
     613        $WPCleverWoobt = new \WPCleverWoobt;
     614
     615        $main_product_metadata['woobt_ids'] = '';
     616        $ids = [];
     617        $linked_products = $WPCleverWoobt->get_product_items( $main_product_id );
     618        foreach ($linked_products as $linked_key => $linked_product){
     619            foreach($simpler_item->get_bundled() as $simpler_bundled_item){
     620                if($simpler_bundled_item['product_id'] == $linked_product['id']){
     621                    $ids[] = $simpler_bundled_item['product_id'].'/'.$linked_key.'/'.$simpler_bundled_item['quantity'];
     622                }
     623            }
     624        }
     625        $main_product_metadata['woobt_ids']=implode(',',$ids);
     626        $WPCleverWoobt->add_to_cart(
     627            $main_product_cart_key,
     628            $main_product_id,
     629            $simpler_item->get_quantity(),
     630            null,
     631            $simpler_item->get_attributes_array(), 
     632            $main_product_metadata
     633        );
     634        $value = $main_product_cart_key;
     635    }
     636    WC()->cart->calculate_totals();
     637    return $value;
     638}
     639add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_woobt_add_simpler_bundle_to_cart', 10, 2);
     640
     641function simplerwc_compat_woobt_get_product_type_of_the_bundle($value,$bundle_type)
     642{
     643    return $value;
     644}
     645add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_woobt_get_product_type_of_the_bundle', 10, 2);
     646
     647function simplerwc_compat_woobt_get_bundle_type_of_the_product($value,$product)
     648{
     649    if($value) return $value;
     650    $linked_products = get_post_meta($product->get_id(), 'woobt_ids', true);
     651    if (!empty($linked_products)) return 'woobt';
     652    return $value;
     653}
     654add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_woobt_get_bundle_type_of_the_product', 10, 2);
     655
     656
     657
     658// WC Linked products
     659function simplerwc_compat_woocommerce_cart_item_is_bundled($value, $cart_item)
     660{
     661    if (array_key_exists('bundle_sell_of',$cart_item)) {
     662        return true;
     663    }
     664    return $value;
     665}
     666add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_woocommerce_cart_item_is_bundled', 10, 2);
     667
     668function simplerwc_compat_woocommerce_cart_item_is_bundle_container($value, $cart_item)
     669{
     670    if (isset($cart_item['bundle_sells']) && !empty($cart_item['bundle_sells'])){
     671        return 'woocommerce';
     672    }
     673    return $value;
     674}
     675add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_woocommerce_cart_item_is_bundle_container', 10, 2);
     676
     677function simplerwc_compat_woocommerce_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type)
     678{
     679    if($bundle_type!='woocommerce') return $value;
     680
     681    $bundled_items = [];
     682    $cross_sell_items = $cart_item["bundle_sells"] ?? [];
     683    foreach ($cross_sell_items as $id) {
     684        $bundled_items[] = $cart->get_cart_item($id);
     685    }
     686    return $bundled_items;
     687}
     688add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_woocommerce_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4);
     689
     690function simplerwc_compat_woocommerce_product_is_bundle_container($value, $product)
     691{
     692    $linked_products = get_post_meta($product->get_id(), 'bundle_sells', true);
     693
     694    if (empty($linked_products)) return $value;
     695   
     696    return $value;
     697}
     698add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_woocommerce_product_is_bundle_container', 10, 2);
     699
     700function simplerwc_compat_woocommerce_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type)
     701{
     702    if($bundle_type!='woocommerce') return $value;
     703
     704    return $value;
     705}
     706add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_woocommerce_get_all_products_linked_to_the_bundle_product', 10, 3);
     707
     708function simplerwc_compat_woocommerce_add_simpler_bundle_to_cart($value, $simpler_item)
     709{
     710    if($simpler_item->get_bundle_type()!='woocommerce') return $value;
     711
     712    $main_product_cart_key = \WC()->cart->add_to_cart(
     713        $simpler_item->get_product_id(),
     714        $simpler_item->get_quantity(),
     715        NULL,
     716        $simpler_item->get_attributes_array(),
     717        apply_filters('simplerwc_get_cart_item_data', [], $simpler_item)
     718    );
     719
     720    // Woo Product Bundles configured through Linked Products
     721    foreach ($simpler_item->get_bundled() as $bundled) {
     722        \WC()->cart->add_to_cart(
     723            $bundled['product_id'],
     724            $bundled['quantity'],
     725            NULL,
     726            $bundled['attributes'],
     727            apply_filters('simplerwc_get_cart_item_data', ['bundle_sell_of' => $main_product_cart_key], $bundled)
     728        );
     729    }
     730    if (class_exists('\WC_PB_BS_Cart') && method_exists('\WC_PB_BS_Cart', 'load_bundle_sells_into_session')) {
     731        \WC_PB_BS_Cart::load_bundle_sells_into_session(\WC()->cart);
     732    }
     733    return $main_product_cart_key;
     734}
     735add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_woocommerce_add_simpler_bundle_to_cart', 10, 2);
     736
     737function simplerwc_compat_woocommerce_get_product_type_of_the_bundle($value,$bundle_type)
     738{
     739    return $value;
     740}
     741add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_woocommerce_get_product_type_of_the_bundle', 10, 2);
     742
     743function simplerwc_compat_woocommerce_get_bundle_type_of_the_product($value,$product)
     744{
     745    if($value) return $value;
     746    return 'woocommerce';
     747}
     748add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_woocommerce_get_bundle_type_of_the_product', 11, 2);
     749
  • simpler-checkout/trunk/includes/constants.php

    r3244572 r3257191  
    11<?php
    22
    3 const SIMPLERWC_VERSION = '1.1.1';
     3const SIMPLERWC_VERSION = '1.1.2';
    44
    55function simplerwc_get_sdk_uri()
  • simpler-checkout/trunk/simpler.php

    r3244572 r3257191  
    88 * Description: Simpler Checkout lets your customers complete their purchases in seconds, with any payment method they want, in any device or browser and without a password.
    99 * Tags: woocommerce, checkout, payments, conversion rate
    10  * Version: 1.1.1
     10 * Version: 1.1.2
    1111 * Requires at least: 5.1
    1212 * Tested up to: 6.3.1
  • simpler-checkout/trunk/vendor/autoload.php

    r3244572 r3257191  
    55require_once __DIR__ . '/composer/autoload_real.php';
    66
    7 return ComposerAutoloaderInit0250069f9335df0d3d59ba9ce9dcfb67::getLoader();
     7return ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa::getLoader();
  • simpler-checkout/trunk/vendor/composer/autoload_real.php

    r3244572 r3257191  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit0250069f9335df0d3d59ba9ce9dcfb67
     5class ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa
    66{
    77    private static $loader;
     
    2525        require __DIR__ . '/platform_check.php';
    2626
    27         spl_autoload_register(array('ComposerAutoloaderInit0250069f9335df0d3d59ba9ce9dcfb67', 'loadClassLoader'), true, true);
     27        spl_autoload_register(array('ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa', 'loadClassLoader'), true, true);
    2828        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
    29         spl_autoload_unregister(array('ComposerAutoloaderInit0250069f9335df0d3d59ba9ce9dcfb67', 'loadClassLoader'));
     29        spl_autoload_unregister(array('ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa', 'loadClassLoader'));
    3030
    3131        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
     
    3333            require __DIR__ . '/autoload_static.php';
    3434
    35             call_user_func(\Composer\Autoload\ComposerStaticInit0250069f9335df0d3d59ba9ce9dcfb67::getInitializer($loader));
     35            call_user_func(\Composer\Autoload\ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::getInitializer($loader));
    3636        } else {
    3737            $map = require __DIR__ . '/autoload_namespaces.php';
  • simpler-checkout/trunk/vendor/composer/autoload_static.php

    r3244572 r3257191  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit0250069f9335df0d3d59ba9ce9dcfb67
     7class ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa
    88{
    99    public static $prefixLengthsPsr4 = array (
     
    8686    {
    8787        return \Closure::bind(function () use ($loader) {
    88             $loader->prefixLengthsPsr4 = ComposerStaticInit0250069f9335df0d3d59ba9ce9dcfb67::$prefixLengthsPsr4;
    89             $loader->prefixDirsPsr4 = ComposerStaticInit0250069f9335df0d3d59ba9ce9dcfb67::$prefixDirsPsr4;
    90             $loader->classMap = ComposerStaticInit0250069f9335df0d3d59ba9ce9dcfb67::$classMap;
     88            $loader->prefixLengthsPsr4 = ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::$prefixLengthsPsr4;
     89            $loader->prefixDirsPsr4 = ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::$prefixDirsPsr4;
     90            $loader->classMap = ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::$classMap;
    9191
    9292        }, null, ClassLoader::class);
  • simpler-checkout/trunk/vendor/composer/installed.php

    r3244572 r3257191  
    11<?php return array(
    22    'root' => array(
    3         'pretty_version' => '1.1.1',
    4         'version' => '1.1.1.0',
     3        'pretty_version' => '1.1.2',
     4        'version' => '1.1.2.0',
    55        'type' => 'wordpress-plugin',
    66        'install_path' => __DIR__ . '/../../',
    77        'aliases' => array(),
    8         'reference' => 'bb55c256e100142e4cc55de1af03ca9bcf581777',
     8        'reference' => '8b7d98f2bf87df11c50d0440d830606ab05ad7ef',
    99        'name' => 'simpler-checkout/woo',
    1010        'dev' => false,
     
    1212    'versions' => array(
    1313        'simpler-checkout/woo' => array(
    14             'pretty_version' => '1.1.1',
    15             'version' => '1.1.1.0',
     14            'pretty_version' => '1.1.2',
     15            'version' => '1.1.2.0',
    1616            'type' => 'wordpress-plugin',
    1717            'install_path' => __DIR__ . '/../../',
    1818            'aliases' => array(),
    19             'reference' => 'bb55c256e100142e4cc55de1af03ca9bcf581777',
     19            'reference' => '8b7d98f2bf87df11c50d0440d830606ab05ad7ef',
    2020            'dev_requirement' => false,
    2121        ),
Note: See TracChangeset for help on using the changeset viewer.