クラス
DeliveryForm
ソース ソース
ファイル: src/Components/DeliveryForm/DeliveryForm.php
class DeliveryForm extends VueComponent
{
/**
* Registers hooks for delivery form
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return void
*/
public function init() {
add_action('wp_enqueue_scripts', function () {
$semantic = new Semantic();
$semantic->loadSegmentCss();
$semantic->loadDimmerCss();
});
add_action('wcexaap_checkout_review_delivery_method', [$this, 'deliveryMethod'], 10, 2);
add_action('wcexaap_checkout_review_delivery_date', [$this, 'deliveryDate'], 10, 2);
add_action('wcexaap_checkout_review_delivery_time', [$this, 'deliveryTime'], 10, 2);
}
/**
* Returns component name as is recognized by Vue.
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return string
*/
public function getComponentName() {
return 'deliveryFormComponent';
}
/**
* Prints delivery form component template
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @global array $usces_entries
* @return void
*/
public function template() {
global $usces_entries;
$propsAndEvents = [];
if ($this->controlledComponent === true) {
$propsAndEvents[] = 'v-bind:loading-prop="loading"';
$propsAndEvents[] = 'v-bind:purchase-payload="purchasePayload"';
$propsAndEvents[] = '@update-payload="updatePayload"';
$propsAndEvents[] = '@update-order="updateOrder"';
$propsAndEvents[] = '@update-loading="updateLoading"';
$propsAndEvents[] = '@update-error-messages="updateErrorMessages"';
}
$allPropsAndEvents = join(' ', $propsAndEvents);
?>
<delivery-form-component
inline-template
delivery-method-session-val="<?php echo $this->getDeliveryMethodValue(); ?>"
<?php echo $allPropsAndEvents; ?>
>
<?php ob_start(); ?>
<div>
<div v-cloak v-if="errorMessage" class="error_message" v-html="errorMessage"></div>
<div class="ui basic blurring segment">
<div v-if="loading" class="ui inverted light active dimmer"></div>
<table class="customer_form fade" id="time">
<input type="hidden" id="delivery_pref" value="" />
<?php if (usces_have_shipped()) : ?>
<tr>
<th scope="row"><?php echo esc_html__('shipping option', 'usces'); ?></th>
<td colspan="2">
<?php $this->deliveryMethod(); ?>
</td>
</tr>
<tr>
<th scope="row"><?php echo esc_html__('Delivery date', 'usces'); ?></th>
<td colspan="2">
<?php $this->deliveryDate(
$usces_entries['order']['delivery_date']
); ?>
</td>
</tr>
<tr>
<th scope="row"><?php echo esc_html__('Delivery Time', 'usces'); ?></th>
<td colspan="2">
<?php $this->deliveryTime(
$usces_entries['order']['delivery_time']
); ?>
</td>
</tr>
<?php endif; ?>
</table>
</div>
</div>
<?php $vuehtml = ob_get_contents(); ?>
<?php ob_end_clean(); ?>
<?php
/**
* Filters the delivery form Vue HTML shown on the Quickpay page
*
* @param string $vuehtml
* @param \Aivec\Welcart\SettlementModules\AmazonPay\Components\DeliveryForm\DeliveryForm $instance
*/
echo apply_filters('wcexaap_checkout_review_filter_delivery_form', $vuehtml, $this);
?>
</delivery-form-component>
<?php
}
/**
* Returns delivery method ID from `$usces_entries['order']['delivery_method']`
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @global \usc_e_shop $usces
* @return int
*/
public function getDeliveryMethodValue() {
global $usces;
$sessionVal = isset($_SESSION['usces_entry']['order']['delivery_method'])
? $_SESSION['usces_entry']['order']['delivery_method']
: 0;
/**
* Mirrored Welcart filter
*
* @ignore
*/
$deli_id = apply_filters(
'usces_filter_get_available_delivery_method',
$usces->get_available_delivery_method()
);
if (empty($deli_id)) {
return 1;
}
$cdeliid = count($deli_id);
foreach ($deli_id as $id) {
$index = $usces->get_delivery_method_index($id);
if (0 <= $index) {
if ((int)$id === (int)$sessionVal || 1 === $cdeliid) {
return $id;
}
}
}
return 1;
}
/**
* Injects Vue bindings into html delivery method inputs.
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @global \usc_e_shop $usces
* @return void
*/
public function deliveryMethod() {
global $usces;
/**
* Mirrored Welcart filter
*
* @ignore
*/
$deli_id = apply_filters(
'usces_filter_get_available_delivery_method',
$usces->get_available_delivery_method()
);
if (empty($deli_id)) {
$html = '<p>' . __('No valid shipping methods.', 'usces') . '</p>';
} else {
$html = '<select
name="offer[delivery_method]"
id="delivery_method_select"
class="delivery_time"
onKeyDown="if (event.keyCode == 13) {return false;}"
>' . "\n";
foreach ($deli_id as $id) {
$index = $usces->get_delivery_method_index($id);
if (0 <= $index) {
$html .= "\t<option
value='{$id}'>
" . esc_html($usces->options['delivery_method'][$index]['name']) . "
</option>\n";
}
}
$html .= "</select>\n";
}
/**
* Filters the delivery form method select HTML shown on the Quickpay page
*
* @param string $html
* @param array $deli_id
*/
$html = apply_filters('wcexaap_checkout_review_filter_delivery_method', $html, $deli_id);
echo $html;
}
/**
* Injects Vue bindings into delivery date inputs.
*
* @param string $value
* @param string $out
* @return mixed
*/
public function deliveryDate($value = '', $out = '') {
$html = "<select
name='offer[delivery_date]'
id='delivery_date_select'
class='delivery_date'
>\n";
$html .= "</select>\n";
/**
* Filters the delivery form date select HTML shown on the Quickpay page
*
* @param string $html
*/
$html = apply_filters('wcexaap_checkout_review_filter_delivery_date', $html);
if ($out == 'return') {
return $html;
} else {
echo $html;
}
}
/**
* Injects Vue bindings into delivery time inputs.
*
* @param string $value
* @param string $out
* @return mixed
*/
public function deliveryTime($value = '', $out = '') {
$html = "<div id='delivery_time_limit_message'></div>\n";
$html .= "<select
name='offer[delivery_time]'
id='delivery_time_select'
class='delivery_time'
>\n";
$html .= "</select>\n";
/**
* Filters the delivery form time select HTML shown on the Quickpay page
*
* @param string $html
*/
$html = apply_filters('wcexaap_checkout_review_filter_delivery_time', $html);
if ($out == 'return') {
return $html;
} else {
echo $html;
}
}
}
- deliveryDate — Injects Vue bindings into delivery date inputs.
- deliveryMethod — Injects Vue bindings into html delivery method inputs.
- deliveryTime — Injects Vue bindings into delivery time inputs.
- getComponentName — Returns component name as is recognized by Vue.
- getDeliveryMethodValue — Returns delivery method ID from `$usces_entries['order']['delivery_method']`
- init — Registers hooks for delivery form
- template — Prints delivery form component template