関数
Cart::postComboSetToCart()
$_POST data戻り値 戻り値
ファイル: src/API/Cart.php
public function postComboSetToCart() {
global $wp_query, $usces; // is $wp_query really necessary? who knows...
// set custom key to `inCart` so we can use Welcart's cart class
$_POST['inCart'] = $_POST['wcexicsAddToCart'];
unset($_POST['wcexicsAddToCart']);
$originalpost = $_POST;
$ids = array_keys($_POST['inCart']);
$post_id = (int)$ids[0];
$skus = array_keys($_POST['inCart'][$post_id]);
$skucode = urldecode($skus[0]);
// we need to make sure the item is a combo-set item
$comboset = ComboSet::getComboSetFromSkuCode($post_id, $skucode);
if ($comboset instanceof GenericError) {
PurchaseSanityChecks::exitAddToCartWithError($comboset->message);
}
$pvals = self::getAddToCartPostValues($comboset->getId());
$groupids = $pvals['groupids'];
$itemoptmap = $pvals['itemoptmap'];
// save selections in $_SESSION so that they aren't lost in case of an error redirect
self::setAddToCartSessionVars($comboset->getId(), $groupids, $itemoptmap);
// check that all group IDs and item IDs exist. Check that required groups have selections
$error = PurchaseSanityChecks::comboSetSelectionsAreValid($comboset->getId(), $groupids);
if ($error instanceof GenericError) {
// abort early since other errors don't matter in this case
PurchaseSanityChecks::exitAddToCartWithError($error->message);
}
// check that the combo-set item division is valid for the group item selections
$error = PurchaseSanityChecks::comboSetItemDivisionIsValid($comboset->getId(), $groupids);
if ($error instanceof GenericError) {
PurchaseSanityChecks::exitAddToCartWithError($error->message);
}
// check that item charge types are valid
$error = PurchaseSanityChecks::comboSetItemChargeTypeIsValid($comboset->getId(), $groupids);
if ($error instanceof GenericError) {
PurchaseSanityChecks::exitAddToCartWithError($error->message);
}
// get post data for constructing a cart out of the selected group items
$postdata = self::getInCartPostData($comboset, $groupids, $itemoptmap);
// use `$usces->incart_check()` to check the combo-set SKU and all selected group items
self::inCartCheckComboSet($postdata);
// unset $_SESSION selections since checks passed ($_SESSION['usces_singleitem'] is handled by Welcart)
$this->unsetSessionVars();
// Now we need to construct a cart out of all the group items
$groupitemscart = $this->getGroupItemsCart($postdata)['rawCart'];
// set $this->payload for use in processing the combo-set item
$this->payload = [];
$this->payload['comboSetId'] = $comboset->getId();
$this->payload['groupItemsCart'] = $groupitemscart;
// Add the combo-set item to the cart
add_filter('usces_filter_in_serialize', [$this, 'filterComboSetInSerialize'], 10);
$_POST = $originalpost;
$usces->page = 'cart';
$usces->cart->inCart();
remove_filter('usces_filter_in_serialize', [$this, 'filterComboSetInSerialize']);
// let Welcart handle the rest
add_action('the_post', [$usces, 'action_cartFilter']);
add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_cart');
add_action('template_redirect', [$usces, 'template_redirect']);
}