クラス
Review
Confirm page (review)
ソース ソース
ファイル: src/Views/ConfirmPageReview/Review.php
class Review extends ConfirmPageDI { /** * AmazonPay module instance * * @var AmazonPay */ protected $module; /** * Child components * * @var VueComponentLoader[] */ public $childComponents; /** * Amazon checkout details. Used for address error HTML * * @var AmazonCheckoutDetails */ protected $checkoutDetailsComp; /** * Amazon Pay product type * * Should be either `payonly` or `payandship` * * @var string */ public $amzProductType; /** * Enqueues necessary assets for this View * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return Review */ public function init() { parent::init(); $chargetype = 'once'; $amzproducttype = 'PayAndShip'; if (defined('WCEX_DLSELLER')) { if (!dlseller_have_shipped()) { $amzproducttype = 'PayOnly'; } } $opts = $this->module->getActingOpts(); // override Amazon address if Welcart address is preferred in settings $whichAddress = $opts['address_priority']; if ($whichAddress === 'welcart') { $amzproducttype = 'PayOnly'; } // components $this->childComponents = [ 'purchaseButton' => new VueComponentLoader( new ConfirmPurchaseButton($amzproducttype, $chargetype, 'welcart'), true ), ]; $this->amzProductType = strtolower($amzproducttype); // styles Theme::enqueueThemeCss(WCEXAAP_PLUGIN_URL); $semantic = new Semantic(); $semantic->loadMessageCss(); wp_enqueue_style( 'checkout_review', WCEXAAP_PLUGIN_URL . '/src/Views/ConfirmPageReview/Review.css', [], WCEXAAP_VERSION ); // scripts $deps = [Checkout::AMAZON_CHECKOUT_JS_SLUG]; $checkoutSessionId = isset($_REQUEST['amazonCheckoutSessionId']) ? $_REQUEST['amazonCheckoutSessionId'] : ''; $this->checkoutDetailsComp = new AmazonCheckoutDetails($this->module, $checkoutSessionId); if (!empty($this->checkoutDetailsComp->getAddressError())) { (new ChangeActions($this->module))->load( $this->checkoutDetailsComp->getCheckoutSessionId(), ['updateShippingAddressButton1', 'updateShippingAddressButton2'] ); $this->checkoutDetailsComp->loadAddressErrorMessageBoxCss(); $deps[] = ChangeActions::WCEXAAP_CHANGE_ACTIONS_JS_SLUG; } else { wp_enqueue_script( Checkout::AMAZON_CHECKOUT_JS_SLUG, $opts['amzjsurl'] . '/checkout.js', [], WCEXAAP_VERSION, true ); } wp_enqueue_script( 'wcexaap-welcart-checkout-review', WCEXAAP_PLUGIN_URL . '/dist/confirmPage.js', $deps, WCEXAAP_VERSION, true ); // script vars $jsvars = []; $jsvars['childComponents'] = $this->childComponents; $jsvars['payAndShip'] = $amzproducttype === 'PayAndShip'; $jsvars['checkoutSessionId'] = $checkoutSessionId; $jsvars['addressError'] = $this->checkoutDetailsComp->getAddressError(); $jsvars = array_merge($jsvars, $this->module->getScriptInjectionVariables()); wp_localize_script('wcexaap-welcart-checkout-review', AmazonPay::L10N, $jsvars); return $this; } /** * Adds payment method descriptor to payment name in order summary table * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param string $emptystr * @param array $usces_entries * @return string */ protected function filterOrderSummaryTablePaymentName($emptystr, $usces_entries) { $details = $_SESSION['amazonCheckoutSession']; $paymentDescriptor = $details['paymentPreferences'][0]['paymentDescriptor']; $emptystr = ' - ' . $paymentDescriptor; return $emptystr; } /** * Adds 'change address' button to shipping info section header of order summary table * * @author Evan D Shaw <evandanielshaw@gmail.com> * @global array $usces_settings * @param string $shipping_address_info * @param array $data * @param array $values * @param string $applyform * @param int $target_market_count * @return string */ protected function filterShippingAddressInfo( $shipping_address_info, $data, $values, $applyform, $target_market_count ) { global $usces_settings; if ($this->module->getActingOpts()['address_priority'] === 'welcart') { return $shipping_address_info; } // phpcs:disable WordPress.WP.I18n.NoEmptyStrings $type = 'confirm'; switch ($applyform) { case 'JP': $shipping_address_info = $this->checkoutDetailsComp->getAddressTableHeader(); $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'name_pre', 'return'); /** * Mirrored Welcart filter * * @ignore */ $shipping_address_info .= '<tr class="name-row delivery-name-row"><th>' . apply_filters('usces_filters_addressform_name_label', __('Full name', 'usces'), $type, $values, $applyform) . '</th><td>' . sprintf(_x('%s', 'honorific', 'usces'), (esc_html($values['delivery']['name1']) . ' ' . esc_html($values['delivery']['name2']))) . '</td></tr>'; $deli_furigana = ('' == (trim($values['delivery']['name3']) . trim($values['delivery']['name4']))) ? '' : sprintf(_x('%s', 'honorific', 'usces'), (esc_html($values['delivery']['name3']) . ' ' . esc_html($values['delivery']['name4']))); $furigana_delivery = '<tr class="furikana-row delivery-furikana-row"><th>' . __('furigana', 'usces') . '</th><td>' . $deli_furigana . '</td></tr>'; /** * Mirrored Welcart filter * * @ignore */ $shipping_address_info .= apply_filters('usces_filter_furigana_confirm_delivery', $furigana_delivery, $type, $values); $shipping_address_info .= usces_custom_field_info($values, 'delivery', 'name_after', 'return'); $shipping_address_info .= '<tr class="zipcode-row delivery-zipcode-row"><th>' . __('Zip/Postal Code', 'usces') . '</th><td>' . esc_html($values['delivery']['zipcode']) . '</td></tr>'; if (1 < $target_market_count) { $shipping_country = (!empty($usces_settings['country'][$values['delivery']['country']])) ? $usces_settings['country'][$values['delivery']['country']] : ''; $shipping_address_info .= '<tr class="country-row delivery-country-row"><th>' . __('Country', 'usces') . '</th><td>' . esc_html($shipping_country) . '</td></tr>'; } $delivery_pref = ($values['delivery']['pref'] == __('-- Select --', 'usces') || $values['delivery']['pref'] == '-- Select --') ? '' : $values['delivery']['pref']; $shipping_address_info .= ' <tr class="states-row delivery-states-row"><th>' . __('Province', 'usces') . '</th><td>' . esc_html($delivery_pref) . '</td></tr> <tr class="address1-row delivery-address1-row"><th>' . __('city', 'usces') . '</th><td>' . esc_html($values['delivery']['address1']) . '</td></tr> <tr class="address2-row delivery-address2-row"><th>' . __('numbers', 'usces') . '</th><td>' . esc_html($values['delivery']['address2']) . '</td></tr> <tr class="address3-row delivery-address3-row"><th>' . __('building name', 'usces') . '</th><td>' . esc_html($values['delivery']['address3']) . '</td></tr> <tr class="tel-row delivery-tel-row"><th>' . __('Phone number', 'usces') . '</th><td>' . esc_html($values['delivery']['tel']) . '</td></tr> <tr class="fax-row delivery-fax-row"><th>' . __('FAX number', 'usces') . '</th><td>' . esc_html($values['delivery']['fax']) . '</td></tr>'; $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'fax_after', 'return'); break; case 'CN': $shipping_address_info = $this->checkoutDetailsComp->getAddressTableHeader(); $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'name_pre', 'return'); /** * Mirrored Welcart filter * * @ignore */ $shipping_address_info .= '<tr class="name-row delivery-name-row"><th>' . apply_filters('usces_filters_addressform_name_label', __('Full name', 'usces'), $type, $values, $applyform) . '</th><td>' . sprintf(_x('%s', 'honorific', 'usces'), esc_html(usces_localized_name($values['delivery']['name1'], $values['delivery']['name2'], 'return'))) . '</td></tr>'; $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'name_after', 'return'); if (1 < $target_market_count) { $shipping_country = (!empty($usces_settings['country'][$values['delivery']['country']])) ? $usces_settings['country'][$values['delivery']['country']] : ''; $shipping_address_info .= '<tr class="country-row delivery-country-row"><th>' . __('Country', 'usces') . '</th><td>' . esc_html($shipping_country) . '</td></tr>'; } $delivery_pref = ($values['delivery']['pref'] == __('-- Select --', 'usces') || $values['delivery']['pref'] == '-- Select --') ? '' : $values['delivery']['pref']; $shipping_address_info .= ' <tr class="states-row delivery-states-row"><th>' . __('State', 'usces') . '</th><td>' . esc_html($delivery_pref) . '</td></tr> <tr class="address1-row delivery-address1-row"><th>' . __('city', 'usces') . '</th><td>' . esc_html($values['delivery']['address1']) . '</td></tr> <tr class="address2-row delivery-address2-row"><th>' . __('Address Line1', 'usces') . '</th><td>' . esc_html($values['delivery']['address2']) . '</td></tr> <tr class="address3-row delivery-address3-row"><th>' . __('Address Line2', 'usces') . '</th><td>' . esc_html($values['delivery']['address3']) . '</td></tr> <tr class="zipcode-row delivery-zipcode-row"><th>' . __('Zip', 'usces') . '</th><td>' . esc_html($values['delivery']['zipcode']) . '</td></tr> <tr class="tel-row delivery-tel-row"><th>' . __('Phone number', 'usces') . '</th><td>' . esc_html($values['delivery']['tel']) . '</td></tr> <tr class="fax-row delivery-fax-row"><th>' . __('FAX number', 'usces') . '</th><td>' . esc_html($values['delivery']['fax']) . '</td></tr>'; $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'fax_after', 'return'); break; case 'US': default: $delivery_pref = ($values['delivery']['pref'] == __('-- Select --', 'usces') || $values['delivery']['pref'] == '-- Select --') ? '' : $values['delivery']['pref']; $shipping_address_info = $this->checkoutDetailsComp->getAddressTableHeader(); $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'name_pre', 'return'); /** * Mirrored Welcart filter * * @ignore */ $shipping_address_info .= '<tr class="name-row delivery-name-row"><th>' . apply_filters('usces_filters_addressform_name_label', __('Full name', 'usces'), $type, $values, $applyform) . '</th><td>' . sprintf(_x('%s', 'honorific', 'usces'), (esc_html($values['delivery']['name2']) . ' ' . esc_html($values['delivery']['name1']))) . '</td></tr>'; $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'name_after', 'return'); $shipping_address_info .= ' <tr class="address2-row delivery-address2-row"><th>' . __('Address Line1', 'usces') . '</th><td>' . esc_html($values['delivery']['address2']) . '</td></tr> <tr class="address3-row delivery-address3-row"><th>' . __('Address Line2', 'usces') . '</th><td>' . esc_html($values['delivery']['address3']) . '</td></tr> <tr class="address1-row delivery-address1-row"><th>' . __('city', 'usces') . '</th><td>' . esc_html($values['delivery']['address1']) . '</td></tr> <tr class="states-row delivery-states-row"><th>' . __('State', 'usces') . '</th><td>' . esc_html($delivery_pref) . '</td></tr>'; if (1 < $target_market_count) { $shipping_country = (!empty($usces_settings['country'][$values['delivery']['country']])) ? $usces_settings['country'][$values['delivery']['country']] : ''; $shipping_address_info .= '<tr class="country-row delivery-country-row"><th>' . __('Country', 'usces') . '</th><td>' . esc_html($shipping_country) . '</td></tr>'; } $shipping_address_info .= ' <tr class="zipcode-row delivery-zipcode-row"><th>' . __('Zip', 'usces') . '</th><td>' . esc_html($values['delivery']['zipcode']) . '</td></tr> <tr class="tel-row delivery-tel-row"><th>' . __('Phone number', 'usces') . '</th><td>' . esc_html($values['delivery']['tel']) . '</td></tr> <tr class="fax-row delivery-fax-row"><th>' . __('FAX number', 'usces') . '</th><td>' . esc_html($values['delivery']['fax']) . '</td></tr>'; $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'fax_after', 'return'); break; } // phpcs:enable return $shipping_address_info; } /** * Returns hidden inputs for confirm page redirect route * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return string */ public function getFormRedirectInputs() { $key = WordPressRequestKeyRouteCollector::ROUTE_KEY; $reqroute = isset($_REQUEST[$key]) ? rawurldecode($_REQUEST[$key]) : ''; $sessionId = isset($_REQUEST['amazonCheckoutSessionId']) ? $_REQUEST['amazonCheckoutSessionId'] : ''; ob_start(); ?> <input type="hidden" name="<?php echo WordPressRequestKeyRouteCollector::ROUTE_KEY ?>" value="<?php echo rawurlencode($reqroute) ?>" /> <input type="hidden" name="amazonCheckoutSessionId" value="<?php echo esc_attr($sessionId); ?>" /> <?php return ob_get_clean(); } /** * Adds hidden inputs for confirm page redirect route to points form * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return void */ protected function actionInsidePointsForm() { echo $this->getFormRedirectInputs(); } /** * Adds hidden inputs for confirm page redirect route to coupon form * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param string $emptystring * @param array $usces_entries * @return string */ protected function filterCouponForm($emptystring, $usces_entries) { $emptystring = $this->getFormRedirectInputs(); return $emptystring; } /** * Adds address error message to top of page if one exists * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return void */ protected function confirmPageHeader() { if (!empty($this->checkoutDetailsComp->getAddressError())) { echo $this->checkoutDetailsComp->getAddressErrorMessageBox('updateShippingAddressButton1', 'template-top'); } } /** * Adds address error message to bottom of page if one exists * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return void */ protected function confirmPageFooter() { if (!empty($this->checkoutDetailsComp->getAddressError())) { echo $this->checkoutDetailsComp->getAddressErrorMessageBox('updateShippingAddressButton2', 'template-bottom'); } } /** * Displays Amazon Pay purchase and back button. * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param string $html * @param array $payments * @param string $acting_flag * @param int $rand * @param string $purchase_disabled * @return string */ protected function filterConfirmPagePayButton($html, $payments, $acting_flag, $rand, $purchase_disabled) { /** * Fires above the purchase button section on the Welcart 通常フロー 内容確認 page * * @important * @param array $payments * @param string $acting_flag * @param int $rand * @param string $purchase_disabled */ do_action( 'wcexaap_confirm_page_review_above_purchase_button', $payments, $acting_flag, $rand, $purchase_disabled ); if (!empty($this->amzProductType)) { /** * Fires above the purchase button section on the Welcart 通常フロー 内容確認 page * * @important * @param array $payments * @param string $acting_flag * @param int $rand * @param string $purchase_disabled */ do_action( "wcexaap_confirm_page_review_above_purchase_button_{$this->amzProductType}", $payments, $acting_flag, $rand, $purchase_disabled ); } ob_start(); ?> <div id="checkout_review" class="wcexaap"> <div class="update-payment-method-container"> <div class="ui message" style="display: flex; flex-flow: row nowrap;"> <img id="amazonPayLogo" src="<?php echo WCEXAAP_PLUGIN_URL . '/assets/logo-pay.png'; ?>" height="20px" /> <a id="updatePaymentMethodButton"> <?php /** * Filters the 'Change Payment Method' link text shown on the Welcart 通常フロー 内容確認 page * * @important * @param string $text Default: 'Amazonアカウントで指定したお支払い方法を変更' */ echo esc_html(apply_filters( 'wcexaap_filter_confirm_page_change_payment_method_link_text', __('Change my Amazon payment method', 'wcexaap') )); ?> </a> </div> </div> <?php $this->childComponents['purchaseButton']->templateIfLoad(); ?> </div> <?php $html = ob_get_clean(); return $html; } }
- actionInsidePointsForm — Adds hidden inputs for confirm page redirect route to points form
- confirmPageFooter — Adds address error message to bottom of page if one exists
- confirmPageHeader — Adds address error message to top of page if one exists
- filterConfirmPagePayButton — Displays Amazon Pay purchase and back button.
- filterCouponForm — Adds hidden inputs for confirm page redirect route to coupon form
- filterOrderSummaryTablePaymentName — Adds payment method descriptor to payment name in order summary table
- filterShippingAddressInfo — Adds 'change address' button to shipping info section header of order summary table
- getFormRedirectInputs — Returns hidden inputs for confirm page redirect route
- init — Enqueues necessary assets for this View