関数
Validation::requiredOptionsProvided( int $post_id, string $sku, array $item_option )
Validates option fields and returns a GenericError
instance if any required options are blank or if any input values are malformed. Returns true
if all checks pass.
パラメータ パラメータ
- $post_id
(数値) (必須)
- $sku
(文字列) (必須) If using
wcex_widget_cart
, MUST be URL decoded. If not usingwcex_widget_cart
, MUST be URL encoded. NOTE: the URL encoded SKU MUST NOT be encoded withrawurlencode
. Useurlencode
instead.- $item_option
(配列) (必須)
ファイル: src/API/Validation.php
public function requiredOptionsProvided($post_id, $sku, array $item_option) { global $usces; $errorsm = []; $ioptkeys = $usces->get_itemOptionKey($post_id, true); if ($ioptkeys) { foreach ($ioptkeys as $key => $value) { $optValues = $usces->get_itemOptions(urldecode($value), $post_id); if (0 == $optValues['means']) { // select if ($optValues['essential'] && '#NONE#' == $item_option[$post_id][$sku][$value]) { $errorsm[] = sprintf(__('Chose the %s', 'usces'), urldecode($value)); } } elseif (1 == $optValues['means']) { // multiselect if ($optValues['essential']) { $mselect = 0; foreach ((array)$item_option[$post_id][$sku][$value] as $mvalue) { if (!empty($mvalue) && '#NONE#' != $mvalue) { $mselect++; } } if ($mselect == 0) { $errorsm[] = sprintf(__('Chose the %s', 'usces'), urldecode($value)); } } } elseif (in_array($optValues['means'], [3, 4])) { // radio & checkbox if ($optValues['essential']) { if (!isset($item_option[$post_id][$sku][$value])) { $errorsm[] = sprintf(__('Chose the %s', 'usces'), urldecode($value)); } } } else { // text if ($optValues['essential'] && WCUtils::is_blank($item_option[$post_id][$sku][$value])) { $errorsm[] = sprintf(__('Input the %s', 'usces'), urldecode($value)); } } } } if (!empty($errorsm)) { return $this->master->estore->getErrorResponse(Store::REQUIRED_OPTIONS_MISSING, [$errorsm], [$errorsm]); } return true; }