Plugin Directory


Ignore:
Timestamp:
07/22/2019 08:31:55 AM (7 years ago)
Author:
thrijith
Message:

Tagging version 2.6.1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • laterpay/trunk/application/Module/Purchase.php

    r2113407 r2126510  
    632632            }
    633633
     634            // Final array initialization, and get current options.
     635            $final_purchase_options = [];
     636            $purchase_options_order = (array) $overlay_content_event->get_result();
     637
     638            // Get purchase custom overlay options.
     639            $custom_overlay_options    = get_option( 'lp_custom_overlay_options' );
     640            $purchase_option_order     = $custom_overlay_options['purchase_order'];
     641            $purchase_option_selection = $custom_overlay_options['purchase_selection'];
     642
     643            // Setup purchase options.
     644            $article_individual_price = empty( $purchase_options_order['article'] ) ? [] : $purchase_options_order['article'];
     645            $article_time_passes      = empty( $purchase_options_order['timepasses'] ) ? [] : $purchase_options_order['timepasses'];
     646            $article_subscriptions    = empty( $purchase_options_order['subscriptions'] ) ? [] : $purchase_options_order['subscriptions'];
     647
     648            // Add article to combined purchase options.
     649            if ( ! empty( $article_individual_price ) ) {
     650                $article_individual_price['type'] = 'article';
     651                $final_purchase_options[]         = $article_individual_price;
     652            }
     653
     654            // Add time pass to combined purchase options.
     655            if ( ! empty( $article_time_passes ) ) {
     656                foreach ( $article_time_passes as $article_time_pass ) {
     657                    $article_time_pass['type'] = 'timepass';
     658                    $final_purchase_options[]  = $article_time_pass;
     659                }
     660            }
     661
     662            // Add subscription to combined purchase options.
     663            if ( ! empty( $article_subscriptions ) ) {
     664                foreach ( $article_subscriptions as $article_subscription ) {
     665                    $article_subscription['type'] = 'subscription';
     666                    $final_purchase_options[]     = $article_subscription;
     667                }
     668            }
     669
     670            // Sort by pricing order.
     671            if ( 1 === absint( $purchase_option_order ) ) {
     672                // Least expensive option listed first.
     673                array_multisort( array_column( $final_purchase_options, 'actual_price' ), SORT_ASC, $final_purchase_options );
     674            } elseif ( 2 === absint( $purchase_option_order ) ) {
     675                // Most expensive option listed first.
     676                array_multisort( array_column( $final_purchase_options, 'actual_price' ), SORT_DESC, $final_purchase_options );
     677            }
     678
     679            // Make default purchase option selection.
     680            if ( ! empty( $final_purchase_options ) ) {
     681                $purchase_options_order = $final_purchase_options;
     682                $found_selection        = false;
     683
     684                // Check all options and add 'selected' if conditions match.
     685                foreach ( $purchase_options_order as $key => $single_purchase_option ) {
     686                    if (
     687                        ( 1 === $purchase_option_selection && 'article' === $single_purchase_option['type'] ) ||
     688                        ( 2 === $purchase_option_selection && 'timepass' === $single_purchase_option['type'] ) ||
     689                        ( 3 === $purchase_option_selection && 'subscription' === $single_purchase_option['type'] )
     690                    ) {
     691                        $purchase_options_order[ $key ]['selected'] = true;
     692                        $found_selection                            = true;
     693                        break;
     694                    }
     695
     696                }
     697
     698                // Select the first option if that is the chosen option or no conditions matched above.
     699                if ( 0 === $purchase_option_selection || ! $found_selection ) {
     700                    $purchase_options_order[0]['selected'] = true;
     701                }
     702            }
     703
    634704            $view_args['title']               = ! empty( $overlay_title ) ? $overlay_title : LaterPay_Helper_Appearance::get_current_options( 'header_title' );
    635705            $view_args['benefits']            = $overlay_benefits;
     
    642712            $view_args['overlay_content']     = $event->get_argument( 'overlay_content' );
    643713            $view_args['teaser']              = $event->get_argument( 'teaser' );
    644             $view_args['data']                = (array) $overlay_content_event->get_result();
     714            $view_args['data']                = $purchase_options_order;
    645715            $view_args['icons']               = $this->config->get_section( 'payment.icons' );
    646716            $view_args['notification_text']   = __( 'I already bought this', 'laterpay' );
Note: See TracChangeset for help on using the changeset viewer.