クラス
CartPage
ソース ソース
ファイル: src/Views/CartPage/CartPage.php
class CartPage
{
    /**
     * AmazonPay module instance
     *
     * @var AmazonPay
     */
    public $module;
    /**
     * Registers cart page button filter for Quickpay
     *
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @param AmazonPay $module
     */
    public function __construct(AmazonPay $module) {
        $this->module = $module;
        add_filter('usces_filter_get_cart_button', [$this, 'filterCartButton'], 10, 1);
    }
    /**
     * Enqueues necessary assets for this view.
     *
     * @inheritDoc
     * @return void
     */
    public function enqueueAssets() {
        // styles
        wp_enqueue_style(
            'wcexaap-cartpage',
            /**
             * Filters the URL path to the CSS loaded on the cart page
             *
             * Use this to override the CSS loaded on the cart page
             *
             * @important
             * @param string $csspath
             */
            apply_filters(
                'wcexaap_filter_cart_page_css_path',
                WCEXAAP_PLUGIN_URL . '/src/Views/CartPage/style.css'
            ),
            /**
             * Filters the dependencies of the CSS loaded on the cart page
             *
             * @param array $deps
             */
            apply_filters('wcexaap_filter_cart_page_css_deps', []),
            WCEXAAP_VERSION
        );
        $params = $this->getCheckoutParams();
        (new Checkout($this->module))->load(
            $this->module->restRoutes->createQueryUrl($params['url']),
            'Cart',
            $params['productType']
        );
    }
    /**
     * Returns create session URL for Amazon Pay checkout session
     *
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @return string
     */
    public function getCheckoutParams() {
        $chargetype = 'once';
        $amzproducttype = 'PayAndShip';
        if (defined('WCEX_DLSELLER')) {
            if (!dlseller_have_shipped()) {
                $amzproducttype = 'PayOnly';
            }
        }
        $urlpt = strtolower($amzproducttype);
        return [
            'url' => "/checkout/quickpay/{$urlpt}/{$chargetype}/createSession",
            'productType' => $amzproducttype,
        ];
    }
    /**
     * Returns cart page next button for normal and quickpay checkout options
     *
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @param string $html
     * @return string
     */
    public function filterCartButton($html) {
        if ($this->module->canProcessCart()) {
            $this->enqueueAssets();
            /**
             * Filters the `商品を購入する` text displayed on the cart page next to the
             * Welcart default buttons
             *
             * @important
             * @param string $text
             */
            $checkout_title = apply_filters(
                'wcexaap_filter_cart_page_normal_checkout_title',
                esc_html__('Continue Checkout', 'wcexaap')
            );
            /**
             * Filters the `ログインしてご注文いただけます。` text displayed on the cart page next to the
             * Welcart default buttons
             *
             * @important
             * @param string $text
             */
            $checkout_message = apply_filters(
                'wcexaap_filter_cart_page_normal_checkout_message',
                esc_html__('Login and continue checkout.', 'wcexaap')
            );
            /**
             * Filters the `会員登録なしでもご注文できます。` text displayed on the cart page next to the
             * Welcart default buttons
             *
             * @important
             * @param string $text
             */
            $checkout_submessage = apply_filters(
                'wcexaap_filter_cart_page_normal_checkout_submessage',
                esc_html__('Non-members can also checkout.', 'wcexaap')
            );
            // Cart button segment
            ob_start();
            ?>
            <div class="cart-next">
                <div class="text">
                    <h4><?php echo $checkout_title; ?></h4>
                    <p>
                        <?php echo $checkout_message; ?>
                        <br>
                        <span class="small">
                            <?php echo $checkout_submessage; ?>
                        </span>
                    </p>
                </div>
                <div class="cart-buttons">
                    <?php echo $this->getContinueShoppingButton(); ?>
                    <input
                        name="customerinfo"
                        type="submit"
                        class="pinkButton to_customerinfo_button"
                        value="<?php echo esc_attr__('Checkout', 'wcexaap'); ?>"
                        <?php
                            /**
                             * Mirrored Welcart filter
                             *
                             * @ignore
                             */
                            echo apply_filters(
                                'usces_filter_cart_nextbutton',
                                ' onclick="return uscesCart.cartNext();"'
                            );
                        ?>
                    />
                </div>
            </div>
            <?php
            $cartbutton = ob_get_contents();
            ob_end_clean();
            /**
             * Filters the cart buttons row HTML on the cart page
             *
             * @param string $cartbutton
             * @param string $checkout_title See {@see 'wcexaap_filter_cart_page_normal_checkout_title'}
             * @param string $checkout_message See {@see 'wcexaap_filter_cart_page_normal_checkout_message'}
             * @param string $checkout_submessage See {@see 'wcexaap_filter_cart_page_normal_checkout_submessage'}
             */
            $cartbutton = apply_filters(
                'wcexaap_filter_cart_button_segment',
                $cartbutton,
                $checkout_title,
                $checkout_message,
                $checkout_submessage
            );
            /**
             * Filters the `Amazon アカウントでも決済できます` text displayed on the cart page next to
             * the Amazon Pay button
             *
             * @important
             * @param string $text
             */
            $qp_title = apply_filters(
                'wcexaap_filter_cart_page_quickpay_title',
                esc_html__('Pay with Amazon', 'wcexaap')
            );
            /**
             * Filters the `Amazon.co.jp に登録している情報を使って簡単にお支払いができるサービスです。`
             * text displayed on the cart page next to the Amazon Pay button
             *
             * @important
             * @param string $text
             */
            $qp_message = apply_filters(
                'wcexaap_filter_cart_page_quickpay_message',
                esc_html(__('Use your Amazon account details to make a purchase.', 'wcexaap'))
            );
            // Quickpay Amazon login button segment
            ob_start();
            ?>
                <div class="cart-next amazon-next">
                    <div class="text">
                        <h4>
                            <?php echo $qp_title; ?>
                        </h4>
                        <p>
                            <?php echo $qp_message; ?>
                            <br>
                        </p>
                    </div>
                    <div class="cart-buttons">
                        <?php echo Checkout::getAmazonPayButton(); ?>
                    </div>
                </div>
            <?php
            $quickpaybutton = ob_get_contents();
            ob_end_clean();
            /**
             * Filters the Amazon Pay button row HTML on the cart page
             *
             * @param string $quickpaybutton
             * @param string $qp_title See {@see 'wcexaap_filter_cart_page_quickpay_title'}
             * @param string $qp_message See {@see 'wcexaap_filter_cart_page_quickpay_message'}
             */
            $quickpaybutton = apply_filters(
                'wcexaap_filter_cart_amzpay_button_segment',
                $quickpaybutton,
                $qp_title,
                $qp_message
            );
            $opts = $this->module->getActingOpts();
            $order = [
                'above' => $opts['quickpay_btn_position'] === 'above'
                    ? $quickpaybutton : $cartbutton,
                'below' => $opts['quickpay_btn_position'] === 'below'
                    ? $quickpaybutton : $cartbutton,
            ];
            ob_start();
            ?>
                <div class="line clearfix">
                    <div></div>
                    <div>or</div>
                    <div></div>
                </div>
            <?php
            $clearfixline = ob_get_contents();
            ob_end_clean();
            /**
             * Filters the divider line HTML shown between the Amazon Pay button and Welcart
             * default buttons on the cart page
             *
             * @param string $line
             */
            $clearfixline = apply_filters('wcexaap_filter_cart_page_line_divider', $clearfixline);
            ob_start();
            ?>
                <div id="cart_checkout_box" class="clearfix">
                    <?php echo $order['above']; ?>
                    <?php echo $clearfixline; ?>
                    <?php echo $order['below']; ?>
                </div>
            <?php
            $html = ob_get_contents();
            ob_end_clean();
            /**
             * Filters all of the Amazon Pay plugin HTML shown on the cart page
             *
             * Includes the Amazon Pay button and Welcart default cart buttons
             *
             * @param string $html
             * @param string $cartbutton  See {@see 'wcexaap_filter_cart_button_segment'}
             * @param string $quickpaybutton  See {@see 'wcexaap_filter_cart_amzpay_button_segment'}
             * @param string $checkout_title  See {@see 'wcexaap_filter_cart_page_normal_checkout_title'}
             * @param string $checkout_message  See {@see 'wcexaap_filter_cart_page_normal_checkout_message'}
             * @param string $checkout_submessage  See {@see 'wcexaap_filter_cart_page_normal_checkout_submessage'}
             * @param string $qp_message  See {@see 'wcexaap_filter_cart_page_quickpay_message'}
             * @param string $qp_title See {@see 'wcexaap_filter_cart_page_quickpay_title'}
             * @param string $line See {@see 'wcexaap_filter_cart_page_line_divider'}
             */
            $html = apply_filters(
                'wcexaap_filter_cart_page_next_buttons',
                $html,
                $cartbutton,
                $quickpaybutton,
                $checkout_title,
                $checkout_message,
                $checkout_submessage,
                $qp_message,
                $qp_title,
                $clearfixline
            );
        }
        return $html;
    }
    /**
     * Returns 'Continue Shopping' button for cart page
     *
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @return string
     */
    public function getContinueShoppingButton() {
        global $usces;
        $res = '';
        if ($usces->use_js) {
            /**
             * Mirrored Welcart filter
             *
             * @ignore
             */
            $res = '<input name="previous" type="button" id="previouscart" class="continue_shopping_button" value="' . __('continue shopping', 'usces') . '"' . apply_filters('usces_filter_cart_prebutton', ' onclick="uscesCart.previousCart();"') . ' />';
        } else {
            $res = '<a href="' . get_home_url() . '" class="continue_shopping_button">' . __('continue shopping', 'usces') . '</a>';
        }
        return $res;
    }
}- __construct — Registers cart page button filter for Quickpay
- enqueueAssets — Enqueues necessary assets for this view.
- filterCartButton — Returns cart page next button for normal and quickpay checkout options
- getCheckoutParams — Returns create session URL for Amazon Pay checkout session
- getContinueShoppingButton — Returns 'Continue Shopping' button for cart page